All Modules / Module 3 / Lesson 3 of 4

Creating, copying, moving, and deleting

5 minute read

File Operations in Terminal

Everything you do with files in Finder — create, copy, move, delete — you can do in Terminal. Often faster.

Create a Folder

mkdir makes a directory (folder):

1

Create a test folder on your Desktop:

mkdir ~/Desktop/TestFolder
2

Check that it exists:

ls ~/Desktop

What does "mkdir" stand for? "Make directory." Directory and folder mean the same thing.

Copy Files

cp copies a file. Format: cp source destination

1

Copy your .zshrc to the Desktop:

cp ~/.zshrc ~/Desktop/zshrc-backup

To copy a folder (and everything inside it), add the -r flag:

cp -r ~/Documents/MyFolder ~/Desktop/MyFolderCopy

What does -r mean? It stands for "recursive" — meaning the command will go through the folder and process everything inside it, including subfolders. Without -r, commands like cp and rm only work on individual files, not folders.

Move or Rename Files

mv moves a file. If the destination is in the same folder, it renames instead:

1

Move a file to a new location:

mv ~/Desktop/zshrc-backup ~/Desktop/TestFolder/
2

Rename a file:

mv ~/Desktop/TestFolder/zshrc-backup ~/Desktop/TestFolder/config.txt

Delete Files (Carefully)

rm removes files. Warning: There's no Trash. Files are gone immediately.

1

Delete a file:

rm ~/Desktop/TestFolder/config.txt

To delete a folder and everything in it, you use rm -r (remember, -r means recursive):

Be careful with rm -r! It deletes everything in the folder without asking — permanently. There's no undo. Always double-check the path before pressing Enter.

rm -r ~/Desktop/TestFolder

Key Takeaway

mkdir creates folders. cp copies, mv moves/renames. rm deletes — permanently. Use -r flag for folders.