Thuta Learning
BasicDevOps & Toolsbeginner

Copying and Moving Files with cp, mv

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Understand cp and mv for copying/moving files, without the intimidation
  • Get comfortable trying out commands yourself in the terminal
  • See how these commands are actually useful on a real server or project

Let's think about it this way for a second

cp source destination copies the source file to the destination location, and the original source stays right where it was. mv source destination 'moves' the source to the destination, so nothing is left behind in the original spot. You can also use mv for renaming — if you just want to rename a file, type mv old-name.txt new-name.txt (Linux doesn't have a dedicated 'rename' command by default, so mv pulls double duty). To copy an entire folder, you need cp -r (-r = recursive, meaning copy everything inside it too).

Let's connect this to a real-world scenario

To make a backup, type cp config.txt config.txt.backup and you'll get a safety copy without touching the original file. To relocate an entire project folder, just type mv old-project/ ~/projects/. Pairing cp with the -i (interactive) flag makes it ask for confirmation before overwriting a file with the same name at the destination — a great habit for beginners to build.

Let's try it together in the terminal

bash
cp notes.txt notes-backup.txt
cp -r project/ project-backup/
mv old-name.txt new-name.txt
mv report.pdf ~/Documents/
You should see
A new notes-backup.txt file appears, and the original notes.txt is still there too.

5-minute try-it

Create a file and use cp to make a backup of it. Then use mv to rename that backup to something new.

A quick word of caution

If a file with the same name already exists at the mv or cp destination, it can get overwritten without warning. Add the -i flag if you want to be asked for confirmation first.

Easy traps

  • Trying to copy an entire folder without -r and hitting an error
  • Misusing mv as if it were 'copy with delete' when you actually wanted to keep a backup

Now try it yourself

Create a file and use cp to make a backup of it. Then use mv to rename that backup to something new.

You'll know it worked when: A new notes-backup.txt file appears, and the original notes.txt is still there too.

Copying and Moving Files with cp, mv | Thuta Learning