Move Directory In Linux

Directories are used to store other directories and files in a hierarchycal way. Some time we may need to move directories to the different paths or inside another directory. Linux provides the mv command in order to move directories. There are different ways to move directories in Linux like multiple move, verbose move, approve every move etc. In this tutorial we examine how to move directory in Linux.

Move Directory

A directory can be moved by using the mv command. The source directory is provided as the first parameter and the destination diretory is provided as second parameter. In the following example we move the directory named nmap as mymap .

$ mv nmap mymap

Alternatively we can specify the directory paths as absolute. In the following example we move “/home/ismail/nmap” into the “/var/mymap”.

$ mv /home/ismail/nmap /var/mymap

Paths or directory names may contain spaces or special characters. Using spaces and special characters in bash may create errors and problems. To prevent these errors and problems it is safe to use double quotos while providing the path and directory information like below.

$ mv "/home/ismail/nmap" "/var/my map"

Move Directory Verbosely

A directory may contain other directories and files. During move a lot of files and directories can be moved. These moved directories and files are not displayed by default. We can display all these directories and files verbosely by using the -v option.

$ mv -v /home/ismail/nmap /home/ismail/netscan
renamed '/home/ismail/nmap' -> '/home/ismail/netscan'

Move Multiple Directories

The mv command can be used to move multiple directories at once. The directories we want to move are provided after the mv command and the last parameter is the destination path where all specified directories will be moved. In the following exmaple we move directories “nmap”,”metasploit” and “john” into the “/var/security”.

$ mv nmap metasploit john /var/security

Approve Every Moved Directory

While moving directories we may approve every directory move by using the -i . For every move we are asked for the approval and use y to accept move or n to reject move.

See also  How To Count Files In Directory On Linux?

Do Not Move Existing Directory

In some cases the destination directory may exist already. We can overwrite by using the -n option .

$ mv -n nmap netscan

Move Directory Using File Manager (GUI Way)

Different desktop environments provides different File Manager which can be also used to move directories. In the following example we use the Ubuntu file manager to move directory named “nmap”. First right click to the directory and select the Move to.. like below.

Move Directory

In the following screen select the path you want to move the directory and click to the Select in the upper right.

Select Directory To Move

Leave a Comment