In Linux we can move the directories to a specific folder and protect them by changing their access permission in order to secure the files and data present in those directories. To move the directory from one path to another is much simpler and can be done easily.

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:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/12/echo/How-to-move-a-directory-in-Linux-1.png" data-lazy- height="143" src="data:image/svg xml,” width=”1275″>

The general syntax of moving the directory from one path to another is:

$ mv [options] source destination

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:

$ mv -vf mydirectory1 /home/hammad/Documents

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/12/echo/How-to-move-a-directory-in-Linux-2.png" data-lazy- height="99" src="data:image/svg xml,” width=”1042″>

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:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/12/echo/How-to-move-a-directory-in-Linux-3.png" data-lazy- height="106" src="data:image/svg xml,” width=”1147″>

Only “mydirectory1” is present which means the “mydirectory2” has successfully been moved into to Documents directory, to verify it, use the command:

$ ls /home/hammad/Documents

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/12/echo/How-to-move-a-directory-in-Linux-4.png" data-lazy- height="93" src="data:image/svg xml,” width=”988″>

Similarly, we can move multiple directories using the command:

$ mv -vfi /home/hammad/Documents/mydirectory1 /home/hammad/Documents/mydirectory2 /home/hammad

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/12/echo/How-to-move-a-directory-in-Linux-5.png" data-lazy- height="147" src="data:image/svg xml,” width=”1277″>

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:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/12/echo/How-to-move-a-directory-in-Linux-6.png" data-lazy- height="588" src="data:image/svg xml,” width=”857″>

Choose the “Destination folder” in our case, it is Documents, and then clicks on the “Select” button:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/12/echo/How-to-move-a-directory-in-Linux-7.png" data-lazy- height="389" src="data:image/svg xml,” width=”1040″>

The directory has successfully been moved, open the “Documents” directory to verify the mobility of the mydirectory2 from /home/hammad to /home/hammad/Documents:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/12/echo/How-to-move-a-directory-in-Linux-8.png" data-lazy- height="184" src="data:image/svg xml,” width=”815″>

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.

About the author

<img data-del="avatar" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/12/echo/hammad–150×150.jpg61c81f2262ad1.jpg" height="112" src="data:image/svg xml,” width=”112″>

Hammad Zahid

I’m an Engineering graduate and my passion for IT has brought me to Linux. Now here I’m learning and sharing my knowledge with the world.