cp and mv

The two commands.

cp source destination copies, leaving the original in place.

mv source destination moves, leaving nothing behind.

Both accept many sources followed by one destination, as long as that destination is a directory: cp a.txt b.txt archive/ copies both into archive.

✦ Renaming is moving

There is no rename command, and people find that odd for about a day. Moving a file to a new name in the same directory IS renaming it, because a file's name is simply where it sits in the tree. mv notes.txt archive.txt renames. mv notes.txt old/ moves. It is the same operation asked two different ways.

cp needs -r for directories, for the same reason rm does: copying a directory means copying everything inside it, so the recursion is stated explicitly. mv needs no such flag, because moving a directory does not have to touch its contents at all.

SANKOFA SANDBOX
learner:~$

Watch what the destination being a directory changes.

Try it → Run `cp readme.txt copy.txt` then `ls`. Now run `mv copy.txt projects/` and `ls projects`. Finally `mv projects/copy.txt projects/renamed.txt` and list again.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: The Destination Rule, and Overwriting →
← Back