Move Files And Directories

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

Make File

touch file.txt

Make Directory

mkdir example_folder

View Directory Contents Directory

ls -l
total 8
drwxrwxr-x 2 chris chris 4096 Jul 24 13:23 example_folder
-rw-rw-r-- 1 chris chris    0 Jul 24 13:22 file.txt

Move File To Directory

mv file.txt example_folder

View Directory Contents Directory

ls -l
total 8
drwxrwxr-x 2 chris chris 4096 Jul 24 13:23 example_folder

Change To Directory

cd example_folder

View Directory Contents Directory

ls -l
total 0
-rw-rw-r-- 1 chris chris 0 Jul 24 13:22 file.txt

mv Options:

  • -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
  • -i Prompt if copy would override file