← Linux and the Command Line Lesson 8 of 51 · 10 XP

cp and mv — copying and moving

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

cp a.txt b.txt             # copy a file
cp a.txt backup/           # copy into a folder (the name stays the same)
cp -r src src_backup       # copy a whole folder (-r)
cp -i a.txt b.txt          # ask if b.txt already exists

mv old.txt new.txt         # RENAME
mv file.txt docs/          # move into a folder
mv *.png images/           # move several

Linux has no separate "rename" command: renaming is moving to the same place under a different name.

Careful: cp and mv silently overwrite the destination file if it exists. The -i option asks, -n won't overwrite.

Task. Make a backup copy of the folder site named site_backup, then inside site rename index.htm to index.html and move logo.png into the folder site/img (you need to create it).

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.