11.4 mv: Move (rename) files
mv moves or renames files (or directories). Synopses:
mv [option]... [-T] source dest
mv [option]... source... directory
mv [option]... -t directory source...
- If two file names are given, mv moves the first file to the
second.
- If the --target-directory (-t) option is given, or
failing that if the last file is a directory and the
--no-target-directory (-T) option is not given,
mv moves each source file to the specified
directory, using the sources' names.
mv can move any type of file from one file system to another.
Prior to version 4.0 of the fileutils,
mv could move only regular files between file systems.
For example, now mv can move an entire directory hierarchy
including special device files from one partition to another. It first
uses some of the same code that's used by cp -a to copy the
requested directories and files, then (assuming the copy succeeded)
it removes the originals. If the copy fails, then the part that was
copied to the destination partition is removed. If you were to copy
three directories from one partition to another and the copy of the first
directory succeeded, but the second didn't, the first would be left on
the destination partition and the second and third would be left on the
original partition.
If a destination file exists but is normally unwritable, standard input
is a terminal, and the -f or --force option is not given,
mv prompts the user for whether to replace the file. (You might
own the file, or have write permission on its directory.) If the
response is not affirmative, the file is skipped.
Warning: If you try to move a symlink that points to a directory,
and you specify the symlink with a trailing slash, then mv
doesn't move the symlink but instead moves the directory referenced
by the symlink. See Trailing slashes.
The program accepts the following options. Also see Common options.
- ‘-b’
- ‘--backup[=method]’
- See Backup options.
Make a backup of each file that would otherwise be overwritten or removed.
- ‘-f’
- ‘--force’
- Do not prompt the user before removing a destination file.
- ‘-i’
- ‘--interactive’
- Prompt whether to overwrite each existing destination file, regardless
of its permissions.
If the response is not affirmative, the file is skipped.
- ‘--reply=how’
-
Deprecated: to be removed in 2008.
Specifying --reply=yes is equivalent to using --force.
Specify --reply=no to make mv act as if ‘no’ were
given as a response to every prompt about a destination file.
Specify --reply=query to make mv prompt the user
about each existing destination file.
Note that --reply=no has an effect only when mv would prompt
without -i or equivalent, i.e., when a destination file exists and is
not writable, standard input is a terminal, and no -f (or equivalent)
option is specified.
- ‘-u’
- ‘--update’
- Do not move a non-directory that has an existing destination with the
same or newer modification time.
If the move is across file system boundaries, the comparison is to the
source time stamp truncated to the resolutions of the destination file
system and of the system calls used to update time stamps; this avoids
duplicate work if several ‘mv -u’ commands are executed with the
same source and destination.
- ‘-v’
- ‘--verbose’
- Print the name of each file before moving it.
- ‘--strip-trailing-slashes’
- Remove any trailing slashes from each source argument.
See Trailing slashes.
- ‘-S suffix’
- ‘--suffix=suffix’
- Append suffix to each backup file made with -b.
See Backup options.
- ‘-t directory’
- ‘--target-directory=directory’
- Specify the destination directory.
See Target directory.
- ‘-T’
- ‘--no-target-directory’
- Do not treat the last operand specially when it is a directory or a
symbolic link to a directory. See Target directory.
An exit status of zero indicates success,
and a nonzero value indicates failure.