Technology

How to move a directory in Linux

There is no greater hope in human life than survival. At the same time, it is important to live well. With that in mind, every content on the website is written so that a person can get all the information from here to start his life to make beautifully.

According to that, Technology is one of the topics. It is also a part of life. Read carefully Details of Technology related article

How to move a directory in Linux

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:

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

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:

$ ls /home/hammad/Documents

Similarly, we can move multiple directories using the command:

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

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.

Did you like this article?
Share it on any of the following social media channels below to give us your vote. Your feedback helps us improve.

Other related Technologies ideas you might enjoy

Related Articles

Leave a Reply

Your email address will not be published.

Check Also
Close