Updated April 20, 2023
Introduction to Linux Move Folder
The move command in Linux is a command-line utility that allows one to move one or more files or directories from the source to destination. The Move command can move single or multiple files or directories from source but the destination should be only one path or file. It also gives a prompt before we overwrite and it also gives an option to move only the new files in the destination. In this Topic, we are going to learn about Linux Move Folder and we will show you how to use the Linux Move command with its options. Each option is explained briefly with syntax and screenshots for better understanding.
Syntax of Linux Move Folder:
Below are different syntax which can be used as per the requirement to move folders from source to destination in Linux.
mv source target
mv folder1 folder2 target
mv file folder target
mv -options source target
The Move ‘mv’ command can move single or multiple files or directories from source but the destination should be only one path or file. It also gives a prompt before we overwrite and it also gives an option to move only the new files in the destination.
How to move a folder in Linux?
Below are the options that can be used with mv command in Linux.
Options | Descriptions |
–backup[=CONTROL] | Helps to make a backup of each existing destination file in the server |
-b | It is similar to –backup option but it does not keep an argument |
-f, –force | It will not prompt any option before overwriting |
-i, –interactive | It will prompt options before we overwrite. |
-n, –no-clobber | It does not overwrite an existing file |
–strip-trailing-slashes | This option will remove any trailing slashes from each of the SOURCE argument |
-S, –suffix=SUFFIX | It overrides the general backup suffix |
-t, –target-directory=DIRECTORY | moves all the SOURCE arguments into the target DIRECTORY |
-T, –no-target-directory | It treats the target DESTINATION as a casual file |
-u, –update | It will allow us to move only when the SOURCE file or directory is newer than the target-directory or file or if the destination file is not present. |
-v, –verbose | It explains what is going to be done |
–help | It will display all the options using the help option and will exit |
–version | It displays the output version information and exits |
Examples of Linux Move Folders
Here are the options listed below on how to use move commands when options are passed through it.
Example #1 – No Option
When the move command is used without passing any options, then it will directly overwrite the folder. Syntax and example are given below for better understanding.
Syntax:
mv folder1 folder2
Example:
mv fruits vegetables
ls
Output:
Example #2 – Option -i
By default, move command does not prompt when the folders are overwriting an existing folder. The above screenshot shows that the folder is overwritten without any prompt or warning. But if we want any warnings to be prompted, we can use option ‘-i’.
Syntax:
mv -i folder1 folder2
Example:
mv -i fruits.txt vegetables.txt
Output:
Example #3 – Option -f
When we want to explicitly mention that we do not want to prompt any warnings while overwriting a folder, then we can use option -f.
Syntax:
mv -f folder1 folder2
Example:
mv -f fruits.txt vegetables.txt
Output:
Example #4 – Option -n
If we do not want to overwrite an existing file, we can use option -n. this will not allow us to overwrite an existing file when we use the move command line.
Syntax:
mv -n folder1 new_folder
Example:
mv -n vegetables.txt apple.txt
ls
Output:
Example #5 – Option -b
This option is used when we want to take a backup of the existing destination folder. The option -b will create a backup folder of the destination folder with a tilde(~) appended to it.
Syntax:
mv -b folder1 folder2
Example:
mv -b folder1 folder2
ls
Output:
Example #6 – Option -v
When we want to see what is happening explicitly when we use mv command, we can use -v option to be passed through mv command.
Syntax:
mv -v source destination
Example:
mv -v folder1 folder2
Output:
Conclusion
The move command is a very useful and easy command line command in Linux to move files or folders from source to destination. It is also used to rename files or folders in the system. The Move command can move single or multiple files or directories from source but the destination should be only one path or file. It also gives a prompt before we overwrite and it also gives an option to move only the new files in the destination.
Thus, from the above article, you have learned how to use move command in Linux. Options that can be passed through move command is also explained above with syntax and screenshots for better understanding. Hope you are now familiar with how to move folders in Linux.
Recommended Articles
We hope that this EDUCBA information on “Linux Move Folder” was beneficial to you. You can view EDUCBA’s recommended articles for more information.