Creating, copying and deleting files
20 min · Beginner
Need help? Ask a tutor on WhatsApp (opens in a new tab)Showing steps for Windows. They are marked “On Windows” below.
Five short commands make, show, copy, move and delete files: mkdir, cat, cp, mv and rm. They are faster than clicking when you work with many files, but they act at once and never ask twice, so read each one before you press Enter.
Make folders: mkdir
Every new project starts with folders. mkdir (make directory) creates a folder. Give it a path, such as marks-app/src, and it can create both folders in one go. Priya works in her college-projects folder.
On Windows
In PowerShell, mkdir always creates the missing folders on the way, and prints the folder it made:
PS C:\Users\Priya\college-projects> mkdir marks-app\src Directory: C:\Users\Priya\college-projects\marks-app Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 21-10-2026 10:15 src
- PowerShell created
marks-appfirst, thensrcinside it. The table shows the last folder made. - If the folder already exists, PowerShell says so in red and changes nothing.
Make a file and look inside: cat
You create a file from the terminal and type its text in an editor. Then cat (short for concatenate, "join") prints the file's text, so you can check it without opening the editor.
On Windows
New-Item creates an empty file, and notepad opens it in Notepad:
PS C:\Users\Priya\college-projects> New-Item marks.txtPS C:\Users\Priya\college-projects> notepad marks.txtOutput Directory: C:\Users\Priya\college-projects Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 21-10-2026 10:18 0 marks.txt
- Length
0means the file is empty. Notepad opens it: typePriya 86,Ravi 58andKabir 91on three lines, press Ctrl+S and close Notepad. touch, from Mac guides, is not recognized in PowerShell;New-Itemdoes the same job.
Example 1 · Show the file
PS C:\Users\Priya\college-projects> cat marks.txtPriya 86 Ravi 58 Kabir 91
What this code does
catprinted every line you typed in Notepad, so the file was saved correctly.- For a long file, show only the start or end:
cat marks.txt -Head 2prints the first 2 lines,cat marks.txt -Tail 1the last line.
Copy, move and rename: cp and mv
Recursive means "this folder and everything inside it, at every level". Commands such as cp and rm need the -r option to work on a whole folder instead of a single file.
Before changing marks.txt, Priya keeps a backup. cp (copy) makes a second file and keeps the first; mv (move) moves a file, and a move to a new name is a rename.
Example 2 · A backup, then a rename
PS C:\Users\Priya\college-projects> cp marks.txt marks-backup.txtPS C:\Users\Priya\college-projects> mv marks-backup.txt old-marks.txtPS C:\Users\Priya\college-projects> lsOutput Directory: C:\Users\Priya\college-projects Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 21-10-2026 10:15 marks-app -a---- 21-10-2026 10:20 27 marks.txt -a---- 21-10-2026 10:20 27 old-marks.txt
What this code does
cpmademarks-backup.txtwith the same 27 bytes.mvthen renamed it toold-marks.txt, somarks-backup.txtno longer exists.cpandmvprint nothing when they work; onlylsprinted here.
mv old-marks.txt marks-app moves the file into the marks-app folder. To copy a whole folder, add -r: cp -r marks-app marks-app-backup.
Both cp and mv replace a file with the same name without asking. Check with ls before you copy over something you need.
Delete: rm has no undo
rm (remove) deletes a file: rm old-marks.txt. Files deleted in the terminal do not go to the Recycle Bin or the Trash. They are gone at once.
Example 3 · Deleting a folder needs -r
PS C:\Users\Priya\college-projects> rm marks-appConfirm The item at C:\Users\Priya\college-projects\marks-app has children and the Recurse parameter was not specified. If you continue, all children will be removed with the item. Are you sure you want to continue? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):
What this code does
marks-appis a folder with something inside ("children"), so PowerShell asks first. TypeNand press Enter to keep it. Pressing just Enter means Yes.- When you are sure,
rm -r marks-appdeletes the folder and everything in it without asking.rm -rf, from Mac guides, is an error in PowerShell.
Before any rm -r, run pwd and ls to be sure where you are and what will go. Type the name exactly, and never run rm -r on ~ or on a folder you have not checked.
rm -r ~ /college-projects gets two names, ~ (your whole home folder) and /college-projects. Read every delete command twice before pressing Enter.Next step
Check your understanding
8 quick questions