HowTo: Move A Folder In Linux Using mv Command

How do I move a folder in BSD/Linux/Apple OX or Unix operating system using bash command line option?

You need to use the mv command to move folder, files, and directories in Linux terminal. The syntax is as follows:

mv source target
mv folder1 folder2 target
mv folder1 file1 target
mv -option source target

The following example would move a folder named documents, without changing its name, from the current directory to an existing subdirectory of the current directory named /backups:

ADVERTISEMENTS

mv documents /backups

mv command can be used to move any number of files and folders in a single command. In this example, the following command moves all folders, including all the contents of those directories, from the current directory to the directory called /nas03/users/home/v/vivek

mv * /nas03/users/home/v/vivek

Please note that the asterisk is a wildcard character that represents all files and folders the current directory. In this next example, move only foo and bar folders from the /home/tom directory to the directory called /home/jerry:

mv /home/tom/foo /home/tom/bar /home/jerry

OR

cd /home/tom
mv foo bar /home/jerry

mv can see explain what is being done with the -v option i.e. it shows the name of each file before moving it:

mv -v /home/tom/foo /home/tom/bar /home/jerry

Sample outputs:

`/home/tom/foo/' -> `/home/jerry/foo'
`/home/tom/bar/' -> `/home/jerry/bar'

You can prompt before overwrite i.e. pass the -i option to make mv interactive if the same name files/folder already exists in the destination directory:

mv -i foo /tmp

Sample outputs:

mv: overwrite `/tmp/foo'? 

Other options

Taken from the man page of gnu/mv command:

       --backup[=CONTROL]
              make a backup of each existing destination file
 
       -b     like --backup but does not accept an argument
 
       -f, --force
              do not prompt before overwriting
 
       -n, --no-clobber
              do not overwrite an existing file
 
       If you specify more than one of -i, -f, -n, only the final one takes effect.
 
       --strip-trailing-slashes
              remove any trailing slashes from each SOURCE argument
 
       -S, --suffix=SUFFIX
              override the usual backup suffix
 
       -t, --target-directory=DIRECTORY
              move all SOURCE arguments into DIRECTORY
 
       -T, --no-target-directory
              treat DEST as a normal file
 
       -u, --update
              move only when the SOURCE file is newer than the destination file or when the destination file is missing
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
2 comments… add one
  • Shubham Darlinge Feb 10, 2015 @ 10:53

    You can use Wine to run windows application in linux…

    sudo apt-get install wine

  • Guilherme Sbragia Feb 21, 2017 @ 1:34

    Basicaly just like in windows

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.