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.
|–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.
mv folder1 folder2
mv fruits vegetables ls
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’.
mv -i folder1 folder2
mv -i fruits.txt vegetables.txt
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.
mv -f folder1 folder2
mv -f fruits.txt vegetables.txt
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.
mv -n folder1 new_folder
mv -n vegetables.txt apple.txt ls
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.
mv -b folder1 folder2
mv -b folder1 folder2 ls
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.
mv -v source destination
mv -v folder1 folder2
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.
We hope that this EDUCBA information on “Linux Move Folder” was beneficial to you. You can view EDUCBA’s recommended articles for more information.