Linux mv Command
Learn Linux mv Command with examples
Published
- Linux mv Command
- mv command move file Source to Destination
- mv command to move multiple files
- mv command rename file Source to Destination
- mv command move and rename file both at once
- mv -i command prompt with confirmation to overwrite
- mv -n command instruct never overwrite an existing destination file
- mv -v command verbose explain what is being done
- mv -b command to move file anyway and rename the existing file
- mv Command in Linux (Documentation)
Linux mv Command
In Linux we use “mv” command to move files and directories from one location to the other. mv command also uses to rename SOURCE to DEST.
mv command move file Source to Destination
$ mv /home/Downloads/linux.iso /home/Desktop
# In this example mv command move linux.iso file from Downloads to Desktop folder.
mv command to move multiple files
We can also use the mv command to move multiple files from Source to Destination.
$ mv centostu.iso fedora.iso ~/linux-setup/
# In this example mv command moving multiple files from one location to another.
mv command rename file Source to Destination
$ mv linux.iso linux-distro.iso
# In this example mv command rename linux.iso file to linux-distro.iso.
mv command move and rename file both at once
$ mv linux.iso ../linux-distro.iso
# In this example mv command rename linux.iso file to linux-distro.iso and also move it one level up.
mv -i command prompt with confirmation to overwrite
By default, the mv command will overwrite the destination file if it already exists. You can override this behavior with the -i option. If we use -i with move command, this will prompt you for confirmation before overwriting a file.
$ mv -i linux.iso ../linux-distro.iso
# In this example mv command rename linux.iso file to linux-distro.iso and also move it one level up.
mv -n command instruct never overwrite an existing destination file
We can use the -n option to instruct the mv command to never overwrite an existing destination file.
$ mv -n linux.iso ../linux-distro.iso
# In this example mv command rename linux.iso file to linux-distro.iso and also move it one level up.
mv -v command verbose explain what is being done
We can use the -v option to instruct the mv command to show details what is being done.
$ mv -v linux.iso ../linux-distro.iso
# In this example mv command rename linux.iso file to linux-distro.iso and also move it one level up. With option -v it will also display the detail what is being done.
mv -b command to move file anyway and rename the existing file
We can also use the mv -b command to move it anyway and rename the existing file.
$ mv -b linux.iso ../linux-distro.iso
# In this example mv -b command to move it anyway and rename the existing file.
mv Command in Linux (Documentation)
NAME
mv - move (rename) files
SYNOPSIS
mv [OPTION]... [-T] SOURCE DEST
mv [OPTION]... SOURCE... DIRECTORY
mv [OPTION]... -t DIRECTORY SOURCE...
DESCRIPTION
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
Mandatory arguments to long options are mandatory for short options too.
--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
-i, --interactive
prompt before overwrite
-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 miss‐
ing
-v, --verbose
explain what is being done
-Z, --context
set SELinux security context of destination file to default type
--help display this help and exit
--version
output version information and exit
The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX. The version control method may be
selected via the --backup option or through the VERSION_CONTROL environment variable. Here are the values:
none, off
never make backups (even if --backup is given)
numbered, t
make numbered backups
existing, nil
numbered if numbered backups exist, simple otherwise
simple, never
always make simple backups