info coreutils

manpagez: man pages & more
info coreutils
Home | html | info | man
File: coreutils.info, Node: mv invocation, Next: rm invocation, Prev: install invocation, Up: Basic operations
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.
 To move a file, ‘mv’ ordinarily simply renames it. However, if
renaming does not work because the destination’s file system differs,
‘mv’ falls back on copying as if by ‘cp -a’, then (assuming the copy
succeeded) it removes the original. If the copy fails, then ‘mv’
removes any partially created copy in the destination. If you were to
copy three directories from one file system to another and the copy of
the first directory succeeded, but the second didn’t, the first would be
left on the destination file system and the second and third would be
left on the original file system.
 ‘mv’ always tries to copy extended attributes (xattr), which may
include SELinux context, ACLs or Capabilities. Upon failure all but
‘Operation not supported’ warnings are output.
 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_: Avoid specifying a source name with a trailing slash, when
it might be a symlink to a directory. Otherwise, ‘mv’ may do something
very surprising, since its behavior depends on the underlying rename
system call. On a system with a modern Linux-based kernel, it fails
with ‘errno=ENOTDIR’. However, on other systems (at least FreeBSD 6.1
and Solaris 10) it silently renames not the symlink but rather the
directory referenced by the symlink. *Note Trailing slashes::.
 _Note_: ‘mv’ will only replace empty directories in the destination.
Conflicting populated directories are skipped with a diagnostic.
 The program accepts the following options. Also see *note Common
options::.
‘-b’
‘--backup[=METHOD]’
 *Note Backup options::. Make a backup of each file that would
 otherwise be overwritten or removed.
‘--debug’
 Print extra information to stdout, explaining how files are copied.
 This option implies the ‘--verbose’ option.
‘-f’
‘--force’
 Do not prompt the user before removing a destination file. If you
 specify more than one of the ‘-i’, ‘-f’, ‘-n’ options, only the
 final one takes effect.
‘-i’
‘--interactive’
 Prompt whether to overwrite each existing destination file,
 regardless of its permissions, and fail if the response is not
 affirmative. If you specify more than one of the ‘-i’, ‘-f’, ‘-n’
 options, only the final one takes effect.
‘-n’
‘--no-clobber’
 Do not overwrite an existing file; silently fail instead. If you
 specify more than one of the ‘-i’, ‘-f’, ‘-n’ options, only the
 final one takes effect. This option is mutually exclusive with
 ‘-b’ or ‘--backup’ option. See also the ‘--update=none’ option
 which will skip existing files but not fail.
‘--no-copy’
 If a file cannot be renamed because the destination file system
 differs, fail with a diagnostic instead of copying and then
 removing the file.
‘-u’
‘--update’
 Do not move a non-directory that has an existing destination with
 the same or newer modification timestamp; instead, silently skip
 the file without failing. If the move is across file system
 boundaries, the comparison is to the source timestamp truncated to
 the resolutions of the destination file system and of the system
 calls used to update timestamps; this avoids duplicate work if
 several ‘mv -u’ commands are executed with the same source and
 destination. This option is ignored if the ‘-n’ or ‘--no-clobber’
 option is also specified.
 WHICH gives more control over which existing files in the
 destination are replaced, and its value can be one of the
 following:
 ‘all’
 This is the default operation when an ‘--update’ option is not
 specified, and results in all existing files in the
 destination being replaced.
 ‘none’
 This is similar to the ‘--no-clobber’ option, in that no files
 in the destination are replaced, but also skipping a file does
 not induce a failure.
 ‘older’
 This is the default operation when ‘--update’ is specified,
 and results in files being replaced if they’re older than the
 corresponding source file.
‘-v’
‘--verbose’
 Print the name of each file before moving it.
‘--strip-trailing-slashes’
 Remove any trailing slashes from each SOURCE argument. *Note
 Trailing slashes::.
‘-S SUFFIX’
‘--suffix=SUFFIX’
 Append SUFFIX to each backup file made with ‘-b’. *Note Backup
 options::.
‘-t DIRECTORY’
‘--target-directory=DIRECTORY’
 Specify the destination DIRECTORY. *Note 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. *Note Target directory::.
‘-Z’
‘--context’
 This option functions similarly to the ‘restorecon’ command, by
 adjusting the SELinux security context according to the system
 default type for destination files and each created directory.
 An exit status of zero indicates success, and a nonzero value
indicates failure.
© manpagez.com 2000-2025
Individual documents may contain additional copyright information.

AltStyle によって変換されたページ (->オリジナル) /