Moving Files

The mv command is used to move a file from one location in the filesystem to another.
mv SOURCE DESTINATION
The mv command requires at least two arguments. The first argument is the source, a path to the file to be moved. The second argument is the destination, a path to where the file will be moved to. The files to be copied are sometimes referred to as the source and the place to where the copies are placed in is called the destination.
Follow Along
Use the following command to switch to the Documents directory:
sysadmin@localhost:~$ cd ~/Documents
To move the people.csv file into the Workdirectory, use the filename as the source, and the directory name as the destination:
sysadmin@localhost:~/Documents$ mv people.csv Work                              
If a file is moved from one directory to another and without specifying a new name for the file, it will retain its original name. The move above can be confirmed using the ls command on the Work directory:
sysadmin@localhost:~/Documents$ ls Work                                         
people.csv
The mv command is able to move multiple files, as long as the final argument provided to the command the destination. For example, to move three files into the School directory:
sysadmin@localhost:~/Documents$ mv numbers.txt food.txt alpha.txt School        
sysadmin@localhost:~/Documents$ ls School                                       
Art  Engineering  Math  alpha.txt  food.txt  numbers.txt  
Moving a file within the same directory is an effective way to rename it. For example, in the following example the animals.txt file is given a new name of zoo.txt:
mv animals.txt zoo.txt
sysadmin@localhost:~/Documents$ ls                                              
School           alpha-second.txt  hidden.txt    newhome.txt                    
Work             alpha-third.txt   letters.txt   os.csv                         
adjectives.txt   animals.txt       linux.txt     profile.txt                    
alpha-first.txt  hello.sh          longfile.txt  red.txt 
sysadmin@localhost:~/Documents$ mv animals.txt zoo.txt                          
sysadmin@localhost:~/Documents$ ls                                              
School           alpha-second.txt  letters.txt   os.csv                         
Work             alpha-third.txt   linux.txt     profile.txt                    
adjectives.txt   hello.sh          longfile.txt  red.txt                        
alpha-first.txt  hidden.txt        newhome.txt   zoo.txt   
​⁠​‌‌⁠⁠⁠⁠​
Consider This
Permissions can have an impact on file management commands, such as the mvcommand. Moving a file requires write and execute permissions on both the origin and destination directories.

Comments