Linux mv command

Updated: 04/26/2017 by Computer Hope

About mv

The mv command is used to move or rename files.


mv renames file SOURCE to DEST, or moves the SOURCE file (or files) to DIRECTORY.

mv syntax



--backup[=CONTROL] Make a backup of each existing destination file, using the control method CONTROL. (See Backup Methods below for more about control methods.)
-b Like --backup, but does not accept an argument; the default backup method is used.
-f, --force Do not prompt before overwriting existing files.
-i, --interactive Prompt before overwriting each existing destination file, regardless of the file's permissions. If the answer to the prompt is negative, the file is skipped.
-n, --no-clobber Do not overwrite any existing file.

If you specify more than one of the above options -i, -f, or -n, only the final option specified takes effect.

--strip-trailing-slashes Remove any trailing slashes from each SOURCE argument.
-S, --suffix=SUFFIX Use the suffix SUFFIX for all backup files. The default SUFFIX is "~".
-t, --target-directory=DIRECTORY Move all SOURCE arguments into directory DIRECTORY.
-T, --no-target-directory Treat DEST as a normal file, not as a directory.
-u, --update Perform the move only if the SOURCE file is newer than the destination file, or the destination file does not already exist.
-v, --verbose Operate verbosely.
--help Display a help message, and exit.
--version Output version information, and exit.

Backup Methods

The default ("simple") suffix for backup files is '~', but it can be set differently with the --suffix option or the SIMPLE_BACKUP_SUFFIX environment variable.

The version control method may be selected via the --backup option or through the VERSION_CONTROL environment variable. The possible control methods are:

none, off Never make backups, even if the --backup option is given.
numbered, t Make numbered backups.
existing, nil numbered if numbered backups already exist, simple otherwise.
simple, never Always make simple backups.

mv examples

mv myfile.txt destination-directory

Moves the file myfile.txt to the directory destination-directory.

mv myfile.txt ../

Attempts to move the file myfile.txt into the parent directory.

mv computer\ hope.txt computer\ hope\ 2.txt

Renames the file "computer hope.txt" to "computer hope 2.txt". Here, the file names contain spaces, so the spaces are escaped with a backslash, which protects the words in the file name from being interpreted as separate command arguments.

Tip: If you want to rename a set of files using a regular expression (such as changing filename*.txt to othername*.txt), try the rename command.

cp — Copy files and directories.
ln — Create a link, or a symbolic link, to a file or directory.
rename — Renames multiple files using a regular expression.
rm — Remove a directory.