If the last argument names an existing directory,
mv moves each other given file into a file with the same name in that
directory. Otherwise, if only two files are given, it renames the
first as the second. It is an error if the last argument is not a
directory and more than two files are given.
Thus, mv /a/x/y /b will rename the file /a/x/y into /b/y if /b
was an existing directory, and into /b otherwise.
Let us call the file a given file is going to be moved into its
destination. If
destination exists, and either the -i option is given, or
destination is unwritable, standard input is a terminal, and the
-f option is not given,
mv prompts the user for whether to replace the file, writing a question
to stderr and reading an answer from stdin. If the response
is not affirmative, the file is skipped.
When both
source and
destination are on the same filesystem, they are the same file (just the name is
changed; owner, mode, timestamps remain unchanged).
When they are on different filesystems, the source file is copied
and then deleted.
mv will copy modification time, access time, user and group ID, and mode
if possible.
When copying user and/or group ID fails, the set-user-ID and
set-group-ID bits are cleared in the copy.
The GNU versions of programs like
cp,
mv,
ln,
install and
patch will make a backup of files about to be overwritten, changed or destroyed
if that is desired. That backup files are desired is indicated by
the -b option. How they should be named is specified by the -V option.
In case the name of the backup file is given by the name of the file
extended by a suffix, this suffix is specified by the -S option.
-b, --backup
Make backups of files that are about to be overwritten or removed.
-S SUFFIX, --suffix=SUFFIX
Append
SUFFIX to each backup file made.
If this option is not specified, the value of the
SIMPLE_BACKUP_SUFFIX environment variable is used. And if
SIMPLE_BACKUP_SUFFIX is not set, the default is ~.
-V METHOD, --version-control=METHOD
Specify how backup files are named. The
METHOD argument can be numbered (or t), existing (or nil), or never (or
simple).
If this option is not specified, the value of the
VERSION_CONTROL environment variable is used. And if
VERSION_CONTROL is not set, the default backup type is existing.
This option corresponds to the Emacs variable version-control.
The valid
METHODs are (unique abbreviations are accepted):
t, numbered
Always make numbered backups.
nil, existing
Make numbered backups of files that already have them, simple
backups of the others.
The variables LANG, LC_ALL, LC_COLLATE, LC_CTYPE and LC_MESSAGES have the
usual meaning. For the GNU version, the variables SIMPLE_BACKUP_SUFFIX
and VERSION_CONTROL control backup file naming, as described above.