The one thing most people are confused about is the difference between move and copy command; copy command is used to make the clone of files/directories to some other paths while keeping the original file/directory at its original path, while the move command is used to move the file/directory from its original path and place it to some other path.
In this write-up, we have explained the methods in detail through which we can move the directories from one path to another in Linux.
How to move directory in Linux
There are two methods to move directories from one destination to another in Linux is either by command line method or graphical user interface, both are discussed in detail.
Method 1: Command line method
We have two directories with the name, mydirectory1, and mydirectory2, we can list both of them using the ls command:
The general syntax of moving the directory from one path to another is:
Use the mv command to move the directory from source to some destination and we can use some options along with this command. The options which can be used with the mv command are:
Options | Description |
---|---|
-f | It will overwrite the functions forcibly while moving the directory from source to destination |
-i | It will enable the interactive mode |
-v | It will show you the progress of the command execution |
-u | It will update the destination files |
-z | It will set the security context of the file to the default settings |
-n | It will disable the overwriting in the destination files |
To understand this, we will move the directory mydirectory2 from /home/hammad (current working directory) to /home/hammad/Documents using the command:
We have used the “-f” option in the above command which is used to forcibly move the directories, and list down the contents, using the ls command:
Only “mydirectory1” is present which means the “mydirectory2” has successfully been moved into to Documents directory, to verify it, use the command:
Similarly, we can move multiple directories using the command:
In the above-executed command, we have moved the multiple directories; mydirectory1 and mydirectory2, from /home/hammad/Documents to /home/hammad using the flags “-vfi” where “v” is used to display the progress of executed command, “f” is used to forcibly moved the directory if required, and “i” is used to enabling the interactive mode.
Method 2: Graphical User interface
For the GUI method, go to the destination folder, right-click on the directory you want to move, and choose the move option:
Choose the “Destination folder” in our case, it is Documents, and then clicks on the “Select” button:
The directory has successfully been moved, open the “Documents” directory to verify the mobility of the mydirectory2 from /home/hammad to /home/hammad/Documents:
Conclusion
The directory can be moved either by using the command line method or GUI method; both are convenient and understandable, it’s up to the reader’s choice. In this write-up, we have explained both the methods in detail, the command line method is recommended because with this method you can use other options using the flags.