100 Useful Command-Line Utilities

by Oliver; 2014

8. cp

The command to make a copy of a file is cp:
$ cp file1 file2 
Use the recursive flag, -R, to copy directories plus files:
$ cp -R dir1 dir2  # copy directories
The directory and everything inside it are copied.

Question: what would the following do?
$ cp -R dir1 ../../
Answer: it would make a copy of dir1 up two levels from our current working directory.

Tip: If you're moving a large directory structure with lots of files in them, use rsync instead of cp. If the command fails midway through, rsync can start from where it left off but cp can't.

<PREV   NEXT>