cp, cp -r & mv
Copy, move & rename
Lesson 6 of 20 · 9 min · Module 2: Shape your files
Copies protect your work. Moving and renaming keep it tidy. In Linux, moving and renaming are the same operation.
Start this lesson →Free. No installation: you write and run the code in your browser, and it is checked automatically.
By the end, you’ll be able to…
- Copy files and folders
- Move and rename with mv
- Predict what happens when the target is a folder
The idea
cp source target copies a file. Copy a whole folder with cp -r. mv source target moves a file, and if the target is a new name in the same folder, it simply renames it. If the target is an existing folder, the file goes inside it.
cp notes.txt notes-copy.txt
mv notes-copy.txt Documents/
cp -r projects/website site-copy
01cp keeps the original
After cp, both files exist and are independent. Changing the copy does not change the original.
02Folders need -r
cp refuses to copy a folder unless you add -r (recursive), which copies the folder and everything inside it.
cp projects/website site
cp -r projects/website sitecp: -r not specified; omitting directory 'projects/website'03mv moves or renames
mv old.txt new.txt renames the file. mv file.txt Documents/ moves it into the Documents folder and keeps its name. The original location is empty afterwards.
Your turn
notes.txt to Documents/notes-backup.txt. 2) Rename data/report-2025.txt to data/archive-2025.txt. 3) Copy the whole projects/website folder to website-backup in your home folder.What the checks look for
- Backs up notes.txt into Documents
- Renames the 2025 report
- Copies the whole website folder
Take this with you
cp duplicates, mv relocates, and a new name in the same folder is just a rename.
Go a little further
Copy two files into Documents with a single cp command by listing both before the folder.