Copy Files And Directories

The cp command copy-pastes the file to a destination directory. The mv command moves a file (deleting it from the original directory).

Make File

touch file.txt

Make Directory

mkdir example

View Directory Contents Directory

ls -l
total 4
drwxrwxr-x 2 chris chris 4096 Jul 24 08:49 example
-rw-rw-r-- 1 chris chris    0 Jul 24 08:49 file.txt

Copy File To Directory

cp file.txt example

Change To Directory

cd example

View Directory Contents Directory

ls -l
total 0
-rw-rw-r-- 1 chris chris 0 Jul 24 08:49 file.txt

cp Options:

  • -a Copy with original permissions and attributes
  • -u Copy only files that don’t exist or are newer than files with the same names in the destination directory
  • -v Show verbose description of copy
  • -r Copy directories and files recursively
  • -i Prompt if copy would override file