In Linux we can move directories to a specific folder and protect them by changing their access permission to secure the files and data present in those directories. Moving the directory from one path to another is much simpler and can be done easily.
The only thing that confuses most people is the difference between the move and copy command; the copy command is used to clone files/directories to other paths while keeping the original file/directory in its original path, while the move command is used to move the file/directory from its original path and place it in another path.
In this article, we have explained the methods in detail through which we can move 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 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 using the ls command:
The general syntax of moving the directory from one path to another is:
Use the mv command to move the source directory to some destination and we can use some options along with this command. The options that can be used with the mv command are
:
To understand this, we will move the mydirectory2 directory from /home/hammad (current working directory) to /home/hammad/Documents using the command: We have used the “-f” option in the previous command which is used to forcibly move directories and enumerate contents, using the ls command:
Only “mydirectory1” is present, which means that “mydirectory2” has been successfully moved to the Documents directory, to verify it, use
the command:
Similarly, we can move multiple directories using the command:
<img src="https://linuxhint.com/wp-content/uploads/2021/12/How-to-move-a-directory-in-Linux-5.png" alt=
“
” />
In the command executed above, we have moved the multiple directories; mydirectory1 and mydirectory2, from /home/hammad/Documents to /home/hammad using the “-vfi” flags where “v” is used to show the progress of the executed command, “f” is used to forcefully move the directory if necessary, and “i” is used to enable interactive mode.
Method 2: GUI
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 click the “Select” button:
<img
src=”https://linuxhint.com/wp-content/uploads/2021/12/How-to-move-a-directory-in-Linux-7.png” alt=”” />
The directory has been successfully moved, open the “Documents” directory to verify the mobility of mydirectory2 from
/home/hammad to /home/hammad/Documents:
Conclusion
The directory can be moved using the command-line method or the GUI method; Both are convenient and understandable, it depends on the reader’s choice. In this article, we have explained both methods in detail, the command line method is recommended because with this method you can use other options using the flags.