1MV(1P)                     POSIX Programmer's Manual                    MV(1P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       mv - move files
13

SYNOPSIS

15       mv [-fi] source_file target_file
16
17       mv [-fi] source_file... target_file
18
19

DESCRIPTION

21       In the first synopsis form, the mv utility shall move the file named by
22       the  source_file  operand  to  the  destination  specified  by the tar‐
23       get_file. This first synopsis form is assumed when  the  final  operand
24       does  not  name an existing directory and is not a symbolic link refer‐
25       ring to an existing directory.
26
27       In the second synopsis form,  mv  shall  move  each  file  named  by  a
28       source_file  operand  to  a  destination file in the existing directory
29       named by the target_dir operand, or referenced if target_dir is a  sym‐
30       bolic link referring to an existing directory. The destination path for
31       each source_file shall be the concatenation of the target directory,  a
32       single  slash  character,  and  the  last  pathname  component  of  the
33       source_file.  This second form is assumed when the final operand  names
34       an existing directory.
35
36       If  any  operand  specifies an existing file of a type not specified by
37       the System Interfaces volume of IEEE Std 1003.1-2001, the  behavior  is
38       implementation-defined.
39
40       For each source_file the following steps shall be taken:
41
42        1. If the destination path exists, the -f option is not specified, and
43           either of the following conditions is true:
44
45            a. The permissions of the destination path do not  permit  writing
46               and the standard input is a terminal.
47
48            b. The -i option is specified.
49
50       the  mv  utility shall write a prompt to standard error and read a line
51       from standard input. If the response is not affirmative,  mv  shall  do
52       nothing  more  with  the current source_file and go on to any remaining
53       source_files.
54
55        2. The mv utility shall perform actions  equivalent  to  the  rename()
56           function    defined    in   the   System   Interfaces   volume   of
57           IEEE Std 1003.1-2001, called with the following arguments:
58
59            a. The source_file operand is used as the old argument.
60
61            b. The destination path is used as the new argument.
62
63       If this succeeds, mv shall do nothing more with the current source_file
64       and  go on to any remaining source_files. If this fails for any reasons
65       other than those described for the errno [EXDEV] in the  System  Inter‐
66       faces  volume of IEEE Std 1003.1-2001, mv shall write a diagnostic mes‐
67       sage to standard error, do nothing more with the  current  source_file,
68       and go on to any remaining source_files.
69
70        3. If  the destination path exists, and it is a file of type directory
71           and source_file is not a file of type directory, or it  is  a  file
72           not  of type directory and source_file is a file of type directory,
73           mv shall write a diagnostic message to standard error,  do  nothing
74           more  with  the  current  source_file,  and  go on to any remaining
75           source_files.
76
77        4. If the destination path exists, mv shall attempt to remove it.   If
78           this  fails  for any reason, mv shall write a diagnostic message to
79           standard error, do nothing more with the current  source_file,  and
80           go on to any remaining source_files.
81
82        5. The  file  hierarchy rooted in source_file shall be duplicated as a
83           file hierarchy rooted in the destination path.  If  source_file  or
84           any  of the files below it in the hierarchy are symbolic links, the
85           links themselves shall be  duplicated,  including  their  contents,
86           rather  than  any files to which they refer.  The following charac‐
87           teristics of each file in the file hierarchy shall be duplicated:
88
89            * The time of last data modification and time of last access
90
91            * The user ID and group ID
92
93            * The file mode
94
95       If the user ID, group ID, or file mode of  a  regular  file  cannot  be
96       duplicated,  the file mode bits S_ISUID and S_ISGID shall not be dupli‐
97       cated.
98
99       When files are duplicated to another file  system,  the  implementation
100       may  require  that the process invoking mv has read access to each file
101       being duplicated.
102
103       If the duplication of the file hierarchy fails for any reason, mv shall
104       write  a diagnostic message to standard error, do nothing more with the
105       current source_file, and go on to any remaining source_files.
106
107       If the duplication of the file characteristics fails for any reason, mv
108       shall  write  a  diagnostic message to standard error, but this failure
109       shall not cause mv to modify its exit status.
110
111        6. The file hierarchy rooted in source_file shall be removed. If  this
112           fails  for  any  reason, mv shall write a diagnostic message to the
113           standard error, do nothing more with the current  source_file,  and
114           go on to any remaining source_files.
115

OPTIONS

117       The  mv  utility  shall  conform  to  the  Base  Definitions  volume of
118       IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
119
120       The following options shall be supported:
121
122       -f     Do not prompt for confirmation if the destination  path  exists.
123              Any previous occurrence of the -i option is ignored.
124
125       -i     Prompt for confirmation if the destination path exists. Any pre‐
126              vious occurrence of the -f option is ignored.
127
128
129       Specifying more than one of the -f or -i options shall not  be  consid‐
130       ered  an  error. The last option specified shall determine the behavior
131       of mv.
132

OPERANDS

134       The following operands shall be supported:
135
136       source_file
137              A pathname of a file or directory to be moved.
138
139       target_file
140              A new pathname for the file or directory being moved.
141
142       target_dir
143              A pathname of an existing directory into which to move the input
144              files.
145
146

STDIN

148       The  standard  input shall be used to read an input line in response to
149       each prompt specified in the STDERR section.  Otherwise,  the  standard
150       input shall not be used.
151

INPUT FILES

153       The  input  files  specified  by each source_file operand can be of any
154       file type.
155

ENVIRONMENT VARIABLES

157       The following environment variables shall affect the execution of mv:
158
159       LANG   Provide a default value for the  internationalization  variables
160              that  are  unset  or  null.  (See the Base Definitions volume of
161              IEEE Std 1003.1-2001, Section  8.2,  Internationalization  Vari‐
162              ables  for the precedence of internationalization variables used
163              to determine the values of locale categories.)
164
165       LC_ALL If set to a non-empty string value, override the values  of  all
166              the other internationalization variables.
167
168       LC_COLLATE
169
170              Determine  the  locale  for  the behavior of ranges, equivalence
171              classes, and multi-character  collating  elements  used  in  the
172              extended  regular expression defined for the yesexpr locale key‐
173              word in the LC_MESSAGES category.
174
175       LC_CTYPE
176              Determine the locale for  the  interpretation  of  sequences  of
177              bytes  of  text  data as characters (for example, single-byte as
178              opposed to multi-byte characters in arguments and input  files),
179              the  behavior  of character classes used in the extended regular
180              expression defined for the yesexpr locale keyword in the LC_MES‐
181              SAGES category.
182
183       LC_MESSAGES
184              Determine the locale for the processing of affirmative responses
185              that should be used to affect the format and contents  of  diag‐
186              nostic messages written to standard error.
187
188       NLSPATH
189              Determine the location of message catalogs for the processing of
190              LC_MESSAGES .
191
192

ASYNCHRONOUS EVENTS

194       Default.
195

STDOUT

197       Not used.
198

STDERR

200       Prompts shall be written to the standard  error  under  the  conditions
201       specified  in  the  DESCRIPTION  section. The prompts shall contain the
202       destination pathname, but their format is otherwise unspecified.   Oth‐
203       erwise, the standard error shall be used only for diagnostic messages.
204

OUTPUT FILES

206       The output files may be of any file type.
207

EXTENDED DESCRIPTION

209       None.
210

EXIT STATUS

212       The following exit values shall be returned:
213
214        0     All input files were moved successfully.
215
216       >0     An error occurred.
217
218

CONSEQUENCES OF ERRORS

220       If the copying or removal of source_file is prematurely terminated by a
221       signal or error, mv may leave a partial  copy  of  source_file  at  the
222       source or destination. The mv utility shall not modify both source_file
223       and the destination path simultaneously; termination at any point shall
224       leave either source_file or the destination path complete.
225
226       The following sections are informative.
227

APPLICATION USAGE

229       Some  implementations  mark  for  update  the st_ctime field of renamed
230       files and some do not. Applications which  make  use  of  the  st_ctime
231       field  may behave differently with respect to renamed files unless they
232       are designed to allow for either behavior.
233

EXAMPLES

235       If the current directory contains only files a (of any type defined  by
236       the  System  Interfaces volume of IEEE Std 1003.1-2001), b (also of any
237       type), and a directory c:
238
239
240              mv a b c
241              mv c d
242
243       results with the original files a and b residing in the directory d  in
244       the current directory.
245

RATIONALE

247       Early  proposals  diverged from the SVID and BSD historical practice in
248       that they required that when the destination path exists, the -f option
249       is  not specified, and input is not a terminal, mv fails. This was done
250       for compatibility with cp. The current text returns to historical prac‐
251       tice.  It  should  be  noted  that this is consistent with the rename()
252       function   defined    in    the    System    Interfaces    volume    of
253       IEEE Std 1003.1-2001,  which  does  not require write permission on the
254       target.
255
256       For absolute clarity, paragraph (1), describing the behavior of mv when
257       prompting for confirmation, should be interpreted in the following man‐
258       ner:
259
260
261              if (exists AND (NOT f_option) AND
262                  ((not_writable AND input_is_terminal) OR i_option))
263
264       The -i option exists on BSD systems, giving applications  and  users  a
265       way  to avoid accidentally unlinking files when moving others. When the
266       standard input is not a terminal, the 4.3 BSD mv deletes  all  existing
267       destination paths without prompting, even when -i is specified; this is
268       inconsistent with the behavior of the 4.3 BSD cp utility, which  always
269       generates  an  error when the file is unwritable and the standard input
270       is not a terminal. The standard developers decided that use of -i is  a
271       request for interaction, so when the destination path exists, the util‐
272       ity takes instructions from whatever responds to standard input.
273
274       The rename() function is able to move directories within the same  file
275       system.  Some historical versions of mv have been able to move directo‐
276       ries, but not to a different file system. The standard developers  con‐
277       sidered  that  this  was  an  annoying inconsistency, so this volume of
278       IEEE Std 1003.1-2001 requires directories to be able to be  moved  even
279       across  file  systems.  There  is no -R option to confirm that moving a
280       directory is actually intended, since such an option was  not  required
281       for  moving  directories in historical practice. Requiring the applica‐
282       tion to specify it sometimes, depending on the destination, seemed just
283       as  inconsistent. The semantics of the rename() function were preserved
284       as much as possible. For example, mv is not permitted to "rename" files
285       to or from directories, even though they might be empty and removable.
286
287       Historic implementations of mv did not exit with a non-zero exit status
288       if they were unable to duplicate any file characteristics when moving a
289       file  across  file systems, nor did they write a diagnostic message for
290       the user. The former behavior has been  preserved  to  prevent  scripts
291       from  breaking;  a diagnostic message is now required, however, so that
292       users are alerted that the file characteristics have changed.
293
294       The exact format of the interactive prompts is  unspecified.  Only  the
295       general  nature of the contents of prompts are specified because imple‐
296       mentations may desire more descriptive prompts than those used on  his‐
297       torical  implementations.  Therefore,  an  application not using the -f
298       option or using the -i option relies on the system to provide the  most
299       suitable  dialog  directly  with the user, based on the behavior speci‐
300       fied.
301
302       When mv is dealing with a single file system and source_file is a  sym‐
303       bolic link, the link itself is moved as a consequence of the dependence
304       on the rename() functionality, per the DESCRIPTION.  Across  file  sys‐
305       tems, this has to be made explicit.
306

FUTURE DIRECTIONS

308       None.
309

SEE ALSO

311       cp, ln, the System Interfaces volume of IEEE Std 1003.1-2001, rename()
312
314       Portions  of  this text are reprinted and reproduced in electronic form
315       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
316       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
317       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
318       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
319       event of any discrepancy between this version and the original IEEE and
320       The  Open Group Standard, the original IEEE and The Open Group Standard
321       is the referee document. The original Standard can be  obtained  online
322       at http://www.opengroup.org/unix/online.html .
323
324
325
326IEEE/The Open Group                  2003                               MV(1P)
Impressum