mv - move files
/usr/bin/mv [-finu] source target_file
/usr/bin/mv [-finu] source... target_dir
/usr/xpg4/bin/mv [-finu] source target_file
/usr/xpg4/bin/mv [-finu] source... target_dir
In the first synopsis form, the mv utility moves the file named by the source operand to the destination specified by the target_file. source and target_file can not have the same name.If target_file does not exist, mv creates a file named target_file.如果 target_file 存在,则将覆盖其内容。使用第一种用法概要形式的前提是最终操作数没有指定现有的目录。
在第二种用法概要形式中,mv 将 source 操作数指定的每个文件移到 target_dir 操作数指定的现有目录中的目标文件。每个 source 的目标路径是目标目录、一个斜杠字符 (/) 以及 source 的最后一个路径名组成部分的串联。使用第二种形式的前提是最终操作数指定了现有目录。
If mv determines that the mode of target_file forbids writing, it prints the mode (see chmod(2)), ask for a response, and read the standard input for one line.If the response is affirmative, the mv occurs, if permissible; otherwise, the command exits.Notice that the mode displayed can not fully represent the access permission if target is associated with an ACL.当 source 的父目录可写入,并且设置了粘滞位时,以下一个或多个条件必须成立:
用户必须拥有文件
用户必须拥有目录
用户必须能够写入文件
用户必须是特权用户
If source is a file and target_file is a link to another file with links, the other links remain and target_file becomes a new file.
If source and target_file/target_dir are on different file systems, mv copies the source and deletes the original.Any hard links to other files are lost. mv attempts to duplicate the source file characteristics to the target, that is, the owner and group id, permission modes, modification and access times, ACLs, and extended attributes, if applicable.对于符号链接,mv 仅保留链接本身的所有者和组。
If unable to preserve owner and group id, mv clears S_ISUID and S_ISGID bits in the target. mv prints a diagnostic message to stderr if unable to clear these bits, though the exit code is not affected. mv might be unable to preserve extended attributes if the target file system does not have extended attribute support. /usr/xpg4/bin/mv prints a diagnostic message to stderr for all other failed attempts to duplicate file characteristics.退出代码不受影响。
要保留源文件特征,用户必须拥有相应的文件访问权限。This includes having the {PRIV_FILE_CHOWN}, {PRIV_FILE_OWNER}, and {PRIV_FILE_SETID} privileges; or having the same owner id as the destination file.
支持以下选项:
mv 在移动文件时不提示,即使在要覆盖现有的 target 目标时也不提示。请注意,这是标准输出不是终端时的缺省行为。
只要移动操作将覆盖现有目标,mv 就会提示确认。无论是否从终端输入,都会执行该操作。如果提示确认失败,这就相当于被用户否决。确定的响应表示应继续移动。其他任何响应都将阻止 mv 覆盖 target。
mv does not overwrite an existing target.
mv moves the file only when the target is older than the source file or when the target is missing.
同时指定 –f 和 –i 选项不算错误。The –f option overrides the –i, –n, and –u options.The –i option overrides the –n and –u options.The –n option overrides the –u option.
同时指定 –f 和 –i 选项不算错误。最后指定的选项决定 mv 的行为。
支持下列操作数:
要移动的文件或目录的路径名。
被移动的文件或目录的新路径名。
要将输入文件移到其中的现有目录的路径名。
See environ(7) for descriptions of the following environment variables that affect the execution of mv: LANG, LC_ALL, LC_COLLATE, LC_CTYPE, LC_MESSAGES, and NLSPATH.
肯定的回答使用为用户语言环境中 LC_MESSAGES 类别的 yesexpr 关键字定义的扩展正则表达式进行处理。LC_COLLATE 类别中指定的语言环境定义为 yesexpr 定义的表达式中使用的范围、等效类和多字符整理元素的行为。LC_CTYPE 中指定的语言环境确定文本数据字符字节序列解释的语言环境,以及为 yesexpr 定义的表达式中使用的字符类的行为。请参见 locale(7)。
将返回以下退出值:
已成功移动所有输入文件。
出现错误。
有关下列属性的说明,请参见 attributes(7):
|
|
cp(1), cpio(1), ln(1), rm(1), chmod(2), attributes(7), environ(7), fsattr(7), privileges(7), standards(7)
-- 允许用户显式标记任何命令行选项的末尾,从而使 mv 可以识别以 - 开头的文件名参数。As an aid to BSD migration, mv accepts - as a synonym for --.将来的版本可能会取消这项迁移辅助功能。
Support for the –n and –u options was added to the mv command in Oracle Solaris 11.4.30.
The /usr/xpg4/bin/mv command was added in the Solaris 2.5 release.
The mv command, with support for the –f and –i options, has been present in all Sun and Oracle releases of Solaris.