417 lines
17 KiB
HTML
417 lines
17 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
|
|
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
|
|
<title>mv</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="mv"></a> <a name="tag_04_90"></a><!-- mv -->
|
|
<!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h4><a name="tag_04_90_01"></a>NAME</h4>
|
|
|
|
<blockquote>mv - move files</blockquote>
|
|
|
|
<h4><a name="tag_04_90_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<p><code><tt>mv</tt> <b>[</b><tt>-fi</tt><b>]</b> <i>source_file target_file</i><tt><br>
|
|
<br>
|
|
mv</tt> <b>[</b><tt>-fi</tt><b>]</b> <i>source_file</i><tt>...</tt> <i>target_file</i><tt><br>
|
|
</tt></code></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_90_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>In the first synopsis form, the <i>mv</i> utility shall move the file named by the <i>source_file</i> operand to the destination
|
|
specified by the <i>target_file</i>. This first synopsis form is assumed when the final operand does not name an existing directory
|
|
and is not a symbolic link referring to an existing directory.</p>
|
|
|
|
<p>In the second synopsis form, <i>mv</i> shall move each file named by a <i>source_file</i> operand to a destination file in the
|
|
existing directory named by the <i>target_dir</i> operand, or referenced if <i>target_dir</i> is a symbolic link referring to an
|
|
existing directory. The destination path for each <i>source_file</i> shall be the concatenation of the target directory, a single
|
|
slash character, and the last pathname component of the <i>source_file</i>. This second form is assumed when the final operand
|
|
names an existing directory.</p>
|
|
|
|
<p>If any operand specifies an existing file of a type not specified by the System Interfaces volume of
|
|
IEEE Std 1003.1-2001, the behavior is implementation-defined.</p>
|
|
|
|
<p>For each <i>source_file</i> the following steps shall be taken:</p>
|
|
|
|
<ol>
|
|
<li>
|
|
<p>If the destination path exists, the <b>-f</b> option is not specified, and either of the following conditions is true:</p>
|
|
|
|
<ol type="a">
|
|
<li>
|
|
<p>The permissions of the destination path do not permit writing and the standard input is a terminal.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The <b>-i</b> option is specified.</p>
|
|
</li>
|
|
</ol>
|
|
|
|
<p>the <i>mv</i> utility shall write a prompt to standard error and read a line from standard input. If the response is not
|
|
affirmative, <i>mv</i> shall do nothing more with the current <i>source_file</i> and go on to any remaining
|
|
<i>source_file</i>s.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The <i>mv</i> utility shall perform actions equivalent to the <a href="../functions/rename.html"><i>rename</i>()</a> function
|
|
defined in the System Interfaces volume of IEEE Std 1003.1-2001, called with the following arguments:</p>
|
|
|
|
<ol type="a">
|
|
<li>
|
|
<p>The <i>source_file</i> operand is used as the <i>old</i> argument.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The destination path is used as the <i>new</i> argument.</p>
|
|
</li>
|
|
</ol>
|
|
|
|
<p>If this succeeds, <i>mv</i> shall do nothing more with the current <i>source_file</i> and go on to any remaining
|
|
<i>source_file</i>s. If this fails for any reasons other than those described for the <i>errno</i> [EXDEV] in the System Interfaces
|
|
volume of IEEE Std 1003.1-2001, <i>mv</i> shall write a diagnostic message to standard error, do nothing more with the
|
|
current <i>source_file</i>, and go on to any remaining <i>source_file</i>s.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>If the destination path exists, and it is a file of type directory and <i>source_file</i> is not a file of type directory, or it
|
|
is a file not of type directory and <i>source_file</i> is a file of type directory, <i>mv</i> shall write a diagnostic message to
|
|
standard error, do nothing more with the current <i>source_file</i>, and go on to any remaining <i>source_file</i>s.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>If the destination path exists, <i>mv</i> shall attempt to remove it. If this fails for any reason, <i>mv</i> shall write a
|
|
diagnostic message to standard error, do nothing more with the current <i>source_file</i>, and go on to any remaining
|
|
<i>source_file</i>s.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The file hierarchy rooted in <i>source_file</i> shall be duplicated as a file hierarchy rooted in the destination path. If
|
|
<i>source_file</i> or any of the files below it in the hierarchy are symbolic links, the links themselves shall be duplicated,
|
|
including their contents, rather than any files to which they refer. The following characteristics of each file in the file
|
|
hierarchy shall be duplicated:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>The time of last data modification and time of last access</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The user ID and group ID</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The file mode</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>If the user ID, group ID, or file mode of a regular file cannot be duplicated, the file mode bits S_ISUID and S_ISGID shall not
|
|
be duplicated.</p>
|
|
|
|
<p>When files are duplicated to another file system, the implementation may require that the process invoking <i>mv</i> has read
|
|
access to each file being duplicated.</p>
|
|
|
|
<p>If the duplication of the file hierarchy fails for any reason, <i>mv</i> shall write a diagnostic message to standard error, do
|
|
nothing more with the current <i>source_file</i>, and go on to any remaining <i>source_file</i>s.</p>
|
|
|
|
<p>If the duplication of the file characteristics fails for any reason, <i>mv</i> shall write a diagnostic message to standard
|
|
error, but this failure shall not cause <i>mv</i> to modify its exit status.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The file hierarchy rooted in <i>source_file</i> shall be removed. If this fails for any reason, <i>mv</i> shall write a
|
|
diagnostic message to the standard error, do nothing more with the current <i>source_file</i>, and go on to any remaining
|
|
<i>source_file</i>s.</p>
|
|
</li>
|
|
</ol>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_90_04"></a>OPTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>mv</i> utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, <a href=
|
|
"../basedefs/xbd_chap12.html#tag_12_02">Section 12.2, Utility Syntax Guidelines</a>.</p>
|
|
|
|
<p>The following options shall be supported:</p>
|
|
|
|
<dl compact>
|
|
<dt><b>-f</b></dt>
|
|
|
|
<dd>Do not prompt for confirmation if the destination path exists. Any previous occurrence of the <b>-i</b> option is ignored.</dd>
|
|
|
|
<dt><b>-i</b></dt>
|
|
|
|
<dd>Prompt for confirmation if the destination path exists. Any previous occurrence of the <b>-f</b> option is ignored.</dd>
|
|
</dl>
|
|
|
|
<p>Specifying more than one of the <b>-f</b> or <b>-i</b> options shall not be considered an error. The last option specified shall
|
|
determine the behavior of <i>mv</i>.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_90_05"></a>OPERANDS</h4>
|
|
|
|
<blockquote>
|
|
<p>The following operands shall be supported:</p>
|
|
|
|
<dl compact>
|
|
<dt><i>source_file</i></dt>
|
|
|
|
<dd>A pathname of a file or directory to be moved.</dd>
|
|
|
|
<dt><i>target_file</i></dt>
|
|
|
|
<dd>A new pathname for the file or directory being moved.</dd>
|
|
|
|
<dt><i>target_dir</i></dt>
|
|
|
|
<dd>A pathname of an existing directory into which to move the input files.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_90_06"></a>STDIN</h4>
|
|
|
|
<blockquote>
|
|
<p>The standard input shall be used to read an input line in response to each prompt specified in the STDERR section. Otherwise,
|
|
the standard input shall not be used.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_90_07"></a>INPUT FILES</h4>
|
|
|
|
<blockquote>
|
|
<p>The input files specified by each <i>source_file</i> operand can be of any file type.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_90_08"></a>ENVIRONMENT VARIABLES</h4>
|
|
|
|
<blockquote>
|
|
<p>The following environment variables shall affect the execution of <i>mv</i>:</p>
|
|
|
|
<dl compact>
|
|
<dt><i>LANG</i></dt>
|
|
|
|
<dd>Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of
|
|
IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> for
|
|
the precedence of internationalization variables used to determine the values of locale categories.)</dd>
|
|
|
|
<dt><i>LC_ALL</i></dt>
|
|
|
|
<dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd>
|
|
|
|
<dt><i>LC_COLLATE</i></dt>
|
|
|
|
<dd><br>
|
|
Determine the locale for the behavior of ranges, equivalence classes, and multi-character collating elements used in the extended
|
|
regular expression defined for the <b>yesexpr</b> locale keyword in the <i>LC_MESSAGES</i> category.</dd>
|
|
|
|
<dt><i>LC_CTYPE</i></dt>
|
|
|
|
<dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as
|
|
opposed to multi-byte characters in arguments and input files), the behavior of character classes used in the extended regular
|
|
expression defined for the <b>yesexpr</b> locale keyword in the <i>LC_MESSAGES</i> category.</dd>
|
|
|
|
<dt><i>LC_MESSAGES</i></dt>
|
|
|
|
<dd>Determine the locale for the processing of affirmative responses that should be used to affect the format and contents of
|
|
diagnostic messages written to standard error.</dd>
|
|
|
|
<dt><i>NLSPATH</i></dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
Determine the location of message catalogs for the processing of <i>LC_MESSAGES .</i> <img src="../images/opt-end.gif" alt=
|
|
"[Option End]" border="0"></dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_90_09"></a>ASYNCHRONOUS EVENTS</h4>
|
|
|
|
<blockquote>
|
|
<p>Default.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_90_10"></a>STDOUT</h4>
|
|
|
|
<blockquote>
|
|
<p>Not used.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_90_11"></a>STDERR</h4>
|
|
|
|
<blockquote>
|
|
<p>Prompts shall be written to the standard error under the conditions specified in the DESCRIPTION section. The prompts shall
|
|
contain the destination pathname, but their format is otherwise unspecified. Otherwise, the standard error shall be used only for
|
|
diagnostic messages.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_90_12"></a>OUTPUT FILES</h4>
|
|
|
|
<blockquote>
|
|
<p>The output files may be of any file type.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_90_13"></a>EXTENDED DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_90_14"></a>EXIT STATUS</h4>
|
|
|
|
<blockquote>
|
|
<p>The following exit values shall be returned:</p>
|
|
|
|
<dl compact>
|
|
<dt> 0</dt>
|
|
|
|
<dd>All input files were moved successfully.</dd>
|
|
|
|
<dt>>0</dt>
|
|
|
|
<dd>An error occurred.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_90_15"></a>CONSEQUENCES OF ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>If the copying or removal of <i>source_file</i> is prematurely terminated by a signal or error, <i>mv</i> may leave a partial
|
|
copy of <i>source_file</i> at the source or destination. The <i>mv</i> utility shall not modify both <i>source_file</i> and the
|
|
destination path simultaneously; termination at any point shall leave either <i>source_file</i> or the destination path
|
|
complete.</p>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_04_90_16"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>Some implementations mark for update the <i>st_ctime</i> field of renamed files and some do not. Applications which make use of
|
|
the <i>st_ctime</i> field may behave differently with respect to renamed files unless they are designed to allow for either
|
|
behavior.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_90_17"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<p>If the current directory contains only files <b>a</b> (of any type defined by the System Interfaces volume of
|
|
IEEE Std 1003.1-2001), <b>b</b> (also of any type), and a directory <b>c</b>:</p>
|
|
|
|
<pre>
|
|
<tt>mv a b c
|
|
mv c d
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>results with the original files <b>a</b> and <b>b</b> residing in the directory <b>d</b> in the current directory.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_90_18"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>Early proposals diverged from the SVID and BSD historical practice in that they required that when the destination path exists,
|
|
the <b>-f</b> option is not specified, and input is not a terminal, <i>mv</i> fails. This was done for compatibility with <a href=
|
|
"../utilities/cp.html"><i>cp</i></a>. The current text returns to historical practice. It should be noted that this is consistent
|
|
with the <a href="../functions/rename.html"><i>rename</i>()</a> function defined in the System Interfaces volume of
|
|
IEEE Std 1003.1-2001, which does not require write permission on the target.</p>
|
|
|
|
<p>For absolute clarity, paragraph (1), describing the behavior of <i>mv</i> when prompting for confirmation, should be interpreted
|
|
in the following manner:</p>
|
|
|
|
<pre>
|
|
<tt>if (exists AND (NOT f_option) AND
|
|
((not_writable AND input_is_terminal) OR i_option))
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>The <b>-i</b> option exists on BSD systems, giving applications and users a way to avoid accidentally unlinking files when
|
|
moving others. When the standard input is not a terminal, the 4.3 BSD <i>mv</i> deletes all existing destination paths without
|
|
prompting, even when <b>-i</b> is specified; this is inconsistent with the behavior of the 4.3 BSD <a href=
|
|
"../utilities/cp.html"><i>cp</i></a> utility, which always generates an error when the file is unwritable and the standard input is
|
|
not a terminal. The standard developers decided that use of <b>-i</b> is a request for interaction, so when the destination path
|
|
exists, the utility takes instructions from whatever responds to standard input.</p>
|
|
|
|
<p>The <a href="../functions/rename.html"><i>rename</i>()</a> function is able to move directories within the same file system.
|
|
Some historical versions of <i>mv</i> have been able to move directories, but not to a different file system. The standard
|
|
developers considered that this was an annoying inconsistency, so this volume of IEEE Std 1003.1-2001 requires
|
|
directories to be able to be moved even across file systems. There is no <b>-R</b> option to confirm that moving a directory is
|
|
actually intended, since such an option was not required for moving directories in historical practice. Requiring the application
|
|
to specify it sometimes, depending on the destination, seemed just as inconsistent. The semantics of the <a href=
|
|
"../functions/rename.html"><i>rename</i>()</a> function were preserved as much as possible. For example, <i>mv</i> is not permitted
|
|
to "rename" files to or from directories, even though they might be empty and removable.</p>
|
|
|
|
<p>Historic implementations of <i>mv</i> did not exit with a non-zero exit status if they were unable to duplicate any file
|
|
characteristics when moving a file across file systems, nor did they write a diagnostic message for the user. The former behavior
|
|
has been preserved to prevent scripts from breaking; a diagnostic message is now required, however, so that users are alerted that
|
|
the file characteristics have changed.</p>
|
|
|
|
<p>The exact format of the interactive prompts is unspecified. Only the general nature of the contents of prompts are specified
|
|
because implementations may desire more descriptive prompts than those used on historical implementations. Therefore, an
|
|
application not using the <b>-f</b> option or using the <b>-i</b> option relies on the system to provide the most suitable dialog
|
|
directly with the user, based on the behavior specified.</p>
|
|
|
|
<p>When <i>mv</i> is dealing with a single file system and <i>source_file</i> is a symbolic link, the link itself is moved as a
|
|
consequence of the dependence on the <a href="../functions/rename.html"><i>rename</i>()</a> functionality, per the DESCRIPTION.
|
|
Across file systems, this has to be made explicit.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_90_19"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_90_20"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="cp.html"><i>cp</i></a> , <a href="ln.html"><i>ln</i></a> , the System Interfaces volume of
|
|
IEEE Std 1003.1-2001, <a href="../functions/rename.html"><i>rename</i>()</a></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_90_21"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 2.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_90_22"></a>Issue 6</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>mv</i> utility is changed to describe processing of symbolic links as specified in the IEEE P1003.2b draft
|
|
standard.</p>
|
|
|
|
<p>The APPLICATION USAGE section is added.</p>
|
|
</blockquote>
|
|
|
|
<div class="box"><em>End of informative text.</em></div>
|
|
|
|
<hr>
|
|
<hr size="2" noshade>
|
|
<center><font size="2"><!--footer start-->
|
|
UNIX ® is a registered Trademark of The Open Group.<br>
|
|
POSIX ® is a registered Trademark of The IEEE.<br>
|
|
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
|
|
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
|
|
]</font></center>
|
|
|
|
<!--footer end-->
|
|
<hr size="2" noshade>
|
|
</body>
|
|
</html>
|
|
|