Moving a folder in Linux is a fundamental task that every Linux user should know how to perform. The process of moving a folder involves relocating a folder from its current location to a new location in the file system. In this article, we will discuss how to move a folder in Linux using the command line interface.
Understanding the mv Command
The mv
command is a built-in command in Linux that is used to move files and folders from one location to another. The syntax of the mv
command is as follows:
mv [options] source destination
Here, source
refers to the file or folder that you want to move, and destination
refers to the new location where you want to move the file or folder.
Moving a Folder in Linux
To move a folder in Linux, you need to use the mv
command with the appropriate options and arguments. Here is the basic syntax of the mv
command to move a folder:
mv [options] source_folder destination_folder
Let’s look at an example to understand how to move a folder in Linux. Suppose you have a folder named my_folder
located in the /home/user/Documents
directory, and you want to move it to the /home/user/Pictures
directory. To do this, you would use the following command:
mv /home/user/Documents/my_folder /home/user/Pictures/
In this command, my_folder
is the source folder, and /home/user/Pictures/
is the destination folder.
You can also use relative paths instead of absolute paths to specify the source and destination folders. For example, if you are currently in the /home/user/Documents
directory, you can use the following command to move the my_folder
folder to the /home/user/Pictures
directory:
mv my_folder ../Pictures/
In this command, ../Pictures/
is the destination folder, and the ..
notation means “one directory up from the current directory.”
Renaming a Folder While Moving
You can also rename a folder while moving it to a new location. To do this, you need to specify the new name for the folder in the destination path. For example, suppose you want to rename the my_folder
folder to new_folder
while moving it to the /home/user/Pictures
directory. You would use the following command:
mv /home/user/Documents/my_folder /home/user/Pictures/new_folder
In this command, new_folder
is the new name for the my_folder
folder.
Moving Multiple Folders
You can also move multiple folders at once using the mv
command. To do this, you need to specify the names of the folders separated by a space in the source path. For example, suppose you have two folders named folder1
and folder2
located in the /home/user/Documents
directory, and you want to move them to the /home/user/Pictures
directory. You would use the following command:
mv /home/user/Documents/folder1 /home/user/Documents/folder2 /home/user/Pictures/
In this command, folder1
and folder2
are the source folders, and /home/user/Pictures/
is the destination folder.
Conclusion
Moving a folder in Linux is a simple task that can be accomplished using the mv
command. The mv
command allows you to move a folder to a new location, rename a folder while moving it, and move multiple folders at once. By mastering this command, you can efficiently manage your files and folders in Linux.