Copying, Moving, and Renaming
Here is the plain idea: once you've made things, you'll want to rearrange them — duplicate a file, move it into another folder, or give it a new name. Three everyday jobs, and they're handled by just two short commands. This is housekeeping for your files, done with words.
You already do all of this with a mouse: drag a file into a folder, copy-paste a document, right-click to rename. The terminal does the same jobs, just by typing the source and the destination.
The photocopier and the moving van
Two pictures cover all three jobs.
Copying is a photocopier. You feed in the original, and out comes a duplicate — the original stays right where it was, and now there are two. Moving is a moving van. The thing leaves its old spot entirely and ends up somewhere new — still one of it, just relocated.
And renaming? That's a quiet surprise: renaming is just moving a thing to the same place under a new name. One command, two uses. We'll see how. 🔦
Copying a file
The command is cp, short for "copy." You give it two things: what to copy, and where the copy should go.
cp notes.txt notes-backup.txt
This reads left to right like a sentence: "copy notes.txt to a new file called notes-backup.txt." Afterward you have both — the original untouched, plus a duplicate. Run ls and you'll see the pair.
You can also copy a file into a folder:
cp notes.txt archive/
That puts a copy of notes.txt inside the archive folder, leaving the original where it was. Copying is the safe, gentle one — it never destroys anything, it only adds.
Moving a file
The command is mv, short for "move." It looks just like cp, but instead of duplicating, it relocates:
mv notes.txt archive/
This moves notes.txt into the archive folder. The original is no longer where it was — there's still only one notes.txt, it just lives somewhere new now. That's the moving van: same single thing, new address.
Renaming with the same command
Here's the quiet surprise from earlier. To rename a file, you "move" it to the same place but with a different name:
mv notes.txt journal.txt
Since you didn't point it at another folder, nothing actually travels anywhere — the file simply ends up called journal.txt instead of notes.txt. To the computer, renaming and moving are the same act: give the thing a new full address, and a new name is just a new address in the same room.
The one thing to watch
This is the moment in the course to slow down, just slightly. Both cp and mv will quietly overwrite a file if the destination name already exists — no warning, no "are you sure?" If you mv notes.txt journal.txt and a journal.txt already lives there, the old one is replaced and gone.
This isn't a reason to be afraid — it's a reason to glance before you leap. Two easy habits keep you safe:
lsfirst. A quick look tells you whether the destination name is already taken.- Ask for a heads-up. Adding the flag
-i(for "interactive") makes the command pause and ask before overwriting:cp -i notes.txt journal.txt. Think of it as a polite "are you sure?" you can switch on whenever you're moving something important.
That's the whole caution. Look first, or ask for the prompt — and you'll never lose something by surprise.
Your turn
In your practice folder, make a file with touch story.txt. Now copy it: cp story.txt story-copy.txt, then ls to see both.
Next, rename the copy: mv story-copy.txt draft.txt, and ls again to confirm. You've duplicated, relocated, and renamed — the everyday housekeeping of files — all with two small commands.
Next up: running a program — actually doing something, not just arranging files. 🐙
Stuck or curious?
Ask Pip about this lesson — tap the porthole bottom-right.