logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

mv.1p (15998B)


  1. '\" et
  2. .TH MV "1P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. mv
  12. \(em move files
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. mv \fB[\fR-if\fB] \fIsource_file target_file\fR
  17. .P
  18. mv \fB[\fR-if\fB] \fIsource_file\fR... \fItarget_dir\fR
  19. .fi
  20. .SH DESCRIPTION
  21. In the first synopsis form, the
  22. .IR mv
  23. utility shall move the file named by the
  24. .IR source_file
  25. operand to the destination specified by the
  26. .IR target_file .
  27. This first synopsis form is assumed when the final operand does not
  28. name an existing directory and is not a symbolic link referring to
  29. an existing directory. In this case, if
  30. .IR source_file
  31. names a non-directory file and
  32. .IR target_file
  33. ends with a trailing
  34. <slash>
  35. character,
  36. .IR mv
  37. shall treat this as an error and no
  38. .IR source_file
  39. operands will be processed.
  40. .P
  41. In the second synopsis form,
  42. .IR mv
  43. shall move each file named by a
  44. .IR source_file
  45. operand to a destination file in the existing directory named by the
  46. .IR target_dir
  47. operand, or referenced if
  48. .IR target_dir
  49. is a symbolic link referring to an existing directory. The
  50. destination path for each
  51. .IR source_file
  52. shall be the concatenation of the target directory, a single
  53. <slash>
  54. character if the target did not end in a
  55. <slash>,
  56. and the last pathname component of the
  57. .IR source_file .
  58. This second form is assumed when the final operand names an existing
  59. directory.
  60. .P
  61. If any operand specifies an existing file of a type not
  62. specified by the System Interfaces volume of POSIX.1\(hy2017, the behavior is implementation-defined.
  63. .P
  64. For each
  65. .IR source_file
  66. the following steps shall be taken:
  67. .IP " 1." 4
  68. If the destination path exists, the
  69. .BR \-f
  70. option is not specified, and either of the following conditions is
  71. true:
  72. .RS 4
  73. .IP " a." 4
  74. The permissions of the destination path do not permit writing and the
  75. standard input is a terminal.
  76. .IP " b." 4
  77. The
  78. .BR \-i
  79. option is specified.
  80. .P
  81. the
  82. .IR mv
  83. utility shall write a prompt to standard error and read a line from
  84. standard input. If the response is not affirmative,
  85. .IR mv
  86. shall do nothing more with the current
  87. .IR source_file
  88. and go on to any remaining
  89. .IR source_file s.
  90. .RE
  91. .IP " 2." 4
  92. If the
  93. .IR source_file
  94. operand and destination path resolve to either the same existing directory
  95. entry or different directory entries for the same existing file, then the
  96. destination path shall not be removed, and one of the following shall
  97. occur:
  98. .RS 4
  99. .IP " a." 4
  100. No change is made to
  101. .IR source_file ,
  102. no error occurs, and no diagnostic is issued.
  103. .IP " b." 4
  104. No change is made to
  105. .IR source_file ,
  106. a diagnostic is issued to standard error identifying the two names,
  107. and the exit status is affected.
  108. .IP " c." 4
  109. If the
  110. .IR source_file
  111. operand and destination path name distinct directory entries, then the
  112. .IR source_file
  113. operand is removed, no error occurs, and no diagnostic is issued.
  114. .P
  115. The
  116. .IR mv
  117. utility shall do nothing more with the current
  118. .IR source_file ,
  119. and go on to any remaining
  120. .IR source_file s.
  121. .RE
  122. .IP " 3." 4
  123. The
  124. .IR mv
  125. utility shall perform actions equivalent to the
  126. \fIrename\fR()
  127. function defined in the System Interfaces volume of POSIX.1\(hy2017, called with the following arguments:
  128. .RS 4
  129. .IP " a." 4
  130. The
  131. .IR source_file
  132. operand is used as the
  133. .IR old
  134. argument.
  135. .IP " b." 4
  136. The destination path is used as the
  137. .IR new
  138. argument.
  139. .P
  140. If this succeeds,
  141. .IR mv
  142. shall do nothing more with the current
  143. .IR source_file
  144. and go on to any remaining
  145. .IR source_file s.
  146. If this fails for any reasons other than those described for the
  147. .IR errno
  148. .BR [EXDEV]
  149. in the System Interfaces volume of POSIX.1\(hy2017,
  150. .IR mv
  151. shall write a diagnostic message to standard error, do nothing more
  152. with the current
  153. .IR source_file ,
  154. and go on to any remaining
  155. .IR source_file s.
  156. .RE
  157. .IP " 4." 4
  158. If the destination path exists, and it is a file of type directory and
  159. .IR source_file
  160. is not a file of type directory, or it is a file not of type directory
  161. and
  162. .IR source_file
  163. is a file of type directory,
  164. .IR mv
  165. shall write a diagnostic message to standard error, do nothing more
  166. with the current
  167. .IR source_file ,
  168. and go on to any remaining
  169. .IR source_file s.
  170. If the destination path exists and was created by a previous step, it
  171. is unspecified whether this will treated as an error or the destination
  172. path will be overwritten.
  173. .IP " 5." 4
  174. If the destination path exists,
  175. .IR mv
  176. shall attempt to remove it. If this fails for any reason,
  177. .IR mv
  178. shall write a diagnostic message to standard error, do nothing more
  179. with the current
  180. .IR source_file ,
  181. and go on to any remaining
  182. .IR source_file s.
  183. .IP " 6." 4
  184. The file hierarchy rooted in
  185. .IR source_file
  186. shall be duplicated as a file hierarchy rooted in the destination path. If
  187. .IR source_file
  188. or any of the files below it in the hierarchy are symbolic links, the
  189. links themselves shall be duplicated, including their contents, rather
  190. than any files to which they refer. The following characteristics of
  191. each file in the file hierarchy shall be duplicated:
  192. .RS 4
  193. .IP " *" 4
  194. The time of last data modification and time of last access
  195. .IP " *" 4
  196. The user ID and group ID
  197. .IP " *" 4
  198. The file mode
  199. .P
  200. If the user ID, group ID, or file mode of a regular file cannot be
  201. duplicated, the file mode bits S_ISUID and S_ISGID shall not be
  202. duplicated.
  203. .P
  204. When files are duplicated to another file system, the implementation
  205. may require that the process invoking
  206. .IR mv
  207. has read access to each file being duplicated.
  208. .P
  209. If files being duplicated to another file system have hard links to
  210. other files, it is unspecified whether the files copied to the new
  211. file system have the hard links preserved or separate copies are created
  212. for the linked files.
  213. .P
  214. If the duplication of the file hierarchy fails for any reason,
  215. .IR mv
  216. shall write a diagnostic message to standard error, do nothing more
  217. with the current
  218. .IR source_file ,
  219. and go on to any remaining
  220. .IR source_file s.
  221. .P
  222. If the duplication of the file characteristics fails for any reason,
  223. .IR mv
  224. shall write a diagnostic message to standard error, but this failure
  225. shall not cause
  226. .IR mv
  227. to modify its exit status.
  228. .RE
  229. .IP " 7." 4
  230. The file hierarchy rooted in
  231. .IR source_file
  232. shall be removed. If this fails for any reason,
  233. .IR mv
  234. shall write a diagnostic message to the standard error, do nothing more
  235. with the current
  236. .IR source_file ,
  237. and go on to any remaining
  238. .IR source_file s.
  239. .SH OPTIONS
  240. The
  241. .IR mv
  242. utility shall conform to the Base Definitions volume of POSIX.1\(hy2017,
  243. .IR "Section 12.2" ", " "Utility Syntax Guidelines".
  244. .P
  245. The following options shall be supported:
  246. .IP "\fB\-f\fP" 10
  247. Do not prompt for confirmation if the destination path exists. Any
  248. previous occurrence of the
  249. .BR \-i
  250. option is ignored.
  251. .IP "\fB\-i\fP" 10
  252. Prompt for confirmation if the destination path exists. Any previous
  253. occurrence of the
  254. .BR \-f
  255. option is ignored.
  256. .P
  257. Specifying more than one of the
  258. .BR \-f
  259. or
  260. .BR \-i
  261. options shall not be considered an error. The last option specified
  262. shall determine the behavior of
  263. .IR mv .
  264. .SH OPERANDS
  265. The following operands shall be supported:
  266. .IP "\fIsource_file\fR" 10
  267. A pathname of a file or directory to be moved.
  268. .IP "\fItarget_file\fR" 10
  269. A new pathname for the file or directory being moved.
  270. .IP "\fItarget_dir\fR" 10
  271. A pathname of an existing directory into which to move the input
  272. files.
  273. .SH STDIN
  274. The standard input shall be used to read an input line in response to
  275. each prompt specified in the STDERR section. Otherwise, the standard
  276. input shall not be used.
  277. .SH "INPUT FILES"
  278. The input files specified by each
  279. .IR source_file
  280. operand can be of any file type.
  281. .SH "ENVIRONMENT VARIABLES"
  282. The following environment variables shall affect the execution of
  283. .IR mv :
  284. .IP "\fILANG\fP" 10
  285. Provide a default value for the internationalization variables that are
  286. unset or null. (See the Base Definitions volume of POSIX.1\(hy2017,
  287. .IR "Section 8.2" ", " "Internationalization Variables"
  288. for the precedence of internationalization variables used to determine
  289. the values of locale categories.)
  290. .IP "\fILC_ALL\fP" 10
  291. If set to a non-empty string value, override the values of all the
  292. other internationalization variables.
  293. .IP "\fILC_COLLATE\fP" 10
  294. .br
  295. Determine the locale for the behavior of ranges, equivalence classes,
  296. and multi-character collating elements used in the extended regular
  297. expression defined for the
  298. .BR yesexpr
  299. locale keyword in the
  300. .IR LC_MESSAGES
  301. category.
  302. .IP "\fILC_CTYPE\fP" 10
  303. Determine the locale for the interpretation of sequences of bytes of
  304. text data as characters (for example, single-byte as opposed to
  305. multi-byte characters in arguments and input files), the behavior of
  306. character classes used in the extended regular expression defined for
  307. the
  308. .BR yesexpr
  309. locale keyword in the
  310. .IR LC_MESSAGES
  311. category.
  312. .IP "\fILC_MESSAGES\fP" 10
  313. .br
  314. Determine the locale used to process affirmative responses, and the
  315. locale used to affect the format and contents of diagnostic messages
  316. and prompts written to standard error.
  317. .IP "\fINLSPATH\fP" 10
  318. Determine the location of message catalogs for the processing of
  319. .IR LC_MESSAGES .
  320. .SH "ASYNCHRONOUS EVENTS"
  321. Default.
  322. .SH STDOUT
  323. Not used.
  324. .SH STDERR
  325. Prompts shall be written to the standard error under the conditions
  326. specified in the DESCRIPTION section. The prompts shall contain the
  327. destination pathname, but their format is otherwise unspecified.
  328. Otherwise, the standard error shall be used only for diagnostic messages.
  329. .SH "OUTPUT FILES"
  330. The output files may be of any file type.
  331. .SH "EXTENDED DESCRIPTION"
  332. None.
  333. .SH "EXIT STATUS"
  334. The following exit values shall be returned:
  335. .IP "\00" 6
  336. All input files were moved successfully.
  337. .IP >0 6
  338. An error occurred.
  339. .SH "CONSEQUENCES OF ERRORS"
  340. If the copying or removal of
  341. .IR source_file
  342. is prematurely terminated by a signal or error,
  343. .IR mv
  344. may leave a partial copy of
  345. .IR source_file
  346. at the source or destination. The
  347. .IR mv
  348. utility shall not modify both
  349. .IR source_file
  350. and the destination path simultaneously; termination at any point shall
  351. leave either
  352. .IR source_file
  353. or the destination path complete.
  354. .LP
  355. .IR "The following sections are informative."
  356. .SH "APPLICATION USAGE"
  357. Some implementations mark for update the last file status change timestamp
  358. of renamed files and some do not. Applications which make use of the
  359. last file status change timestamp may behave differently with respect
  360. to renamed files unless they are designed to allow for either behavior.
  361. .P
  362. The specification ensures that
  363. .IR mv
  364. .BR a
  365. .BR a
  366. will not alter the contents of file
  367. .BR a ,
  368. and allows the implementation to issue an error that a file cannot be
  369. moved onto itself. Likewise, when
  370. .BR a
  371. and
  372. .BR b
  373. are hard links to the same file,
  374. .IR mv
  375. .BR a
  376. .BR b
  377. will not alter
  378. .BR b ,
  379. but if a diagnostic is not issued, then it is unspecified whether
  380. .BR a
  381. is left untouched (as it would be by the
  382. \fIrename\fR()
  383. function) or unlinked (reducing the link count of
  384. .BR b ).
  385. .SH EXAMPLES
  386. If the current directory contains only files
  387. .BR a
  388. (of any type defined by the System Interfaces volume of POSIX.1\(hy2017),
  389. .BR b
  390. (also of any type), and a directory
  391. .BR c :
  392. .sp
  393. .RS 4
  394. .nf
  395. mv a b c
  396. mv c d
  397. .fi
  398. .P
  399. .RE
  400. .P
  401. results with the original files
  402. .BR a
  403. and
  404. .BR b
  405. residing in the directory
  406. .BR d
  407. in the current directory.
  408. .SH RATIONALE
  409. Early proposals diverged from the SVID and BSD historical practice in
  410. that they required that when the destination path exists, the
  411. .BR \-f
  412. option is not specified, and input is not a terminal,
  413. .IR mv
  414. fails. This was done for compatibility with
  415. .IR cp .
  416. The current text returns to historical practice. It should be noted
  417. that this is consistent with the
  418. \fIrename\fR()
  419. function defined in the System Interfaces volume of POSIX.1\(hy2017, which does not require write permission
  420. on the target.
  421. .P
  422. For absolute clarity, paragraph (1), describing the behavior of
  423. .IR mv
  424. when prompting for confirmation, should be interpreted in the following
  425. manner:
  426. .sp
  427. .RS 4
  428. .nf
  429. if (exists AND (NOT f_option) AND
  430. ((not_writable AND input_is_terminal) OR i_option))
  431. .fi
  432. .P
  433. .RE
  434. .P
  435. The
  436. .BR \-i
  437. option exists on BSD systems, giving applications and users a way to
  438. avoid accidentally unlinking files when moving others. When the
  439. standard input is not a terminal, the 4.3 BSD
  440. .IR mv
  441. deletes all existing destination paths without prompting, even when
  442. .BR \-i
  443. is specified; this is inconsistent with the behavior of the 4.3 BSD
  444. .IR cp
  445. utility, which always generates an error when the file is unwritable
  446. and the standard input is not a terminal. The standard developers
  447. decided that use of
  448. .BR \-i
  449. is a request for interaction, so when the destination
  450. path exists, the utility takes instructions from whatever responds to
  451. standard input.
  452. .P
  453. The
  454. \fIrename\fR()
  455. function is able to move directories within the same file system. Some
  456. historical versions of
  457. .IR mv
  458. have been able to move directories, but not to a different file system.
  459. The standard developers considered that this was an annoying
  460. inconsistency, so this volume of POSIX.1\(hy2017 requires directories to be able to be moved
  461. even across file systems. There is no
  462. .BR \-R
  463. option to confirm that moving a directory is actually intended, since
  464. such an option was not required for moving directories in historical
  465. practice. Requiring the application to specify it sometimes, depending
  466. on the destination, seemed just as inconsistent. The semantics of the
  467. \fIrename\fR()
  468. function were preserved as much as possible. For example,
  469. .IR mv
  470. is not permitted to ``rename'' files to or from directories, even
  471. though they might be empty and removable.
  472. .P
  473. Historic implementations of
  474. .IR mv
  475. did not exit with a non-zero exit status if they were unable to
  476. duplicate any file characteristics when moving a file across file
  477. systems, nor did they write a diagnostic message for the user. The
  478. former behavior has been preserved to prevent scripts from breaking; a
  479. diagnostic message is now required, however, so that users are alerted
  480. that the file characteristics have changed.
  481. .P
  482. The exact format of the interactive prompts is unspecified. Only the
  483. general nature of the contents of prompts are specified because
  484. implementations may desire more descriptive prompts than those used on
  485. historical implementations. Therefore, an application not using the
  486. .BR \-f
  487. option or using the
  488. .BR \-i
  489. option relies on the system to provide the most suitable dialog
  490. directly with the user, based on the behavior specified.
  491. .P
  492. When
  493. .IR mv
  494. is dealing with a single file system and
  495. .IR source_file
  496. is a symbolic link, the link itself is moved as a consequence of the
  497. dependence on the
  498. \fIrename\fR()
  499. functionality, per the DESCRIPTION. Across file systems, this has to be
  500. made explicit.
  501. .SH "FUTURE DIRECTIONS"
  502. None.
  503. .SH "SEE ALSO"
  504. .IR "\fIcp\fR\^",
  505. .IR "\fIln\fR\^"
  506. .P
  507. The Base Definitions volume of POSIX.1\(hy2017,
  508. .IR "Chapter 8" ", " "Environment Variables",
  509. .IR "Section 12.2" ", " "Utility Syntax Guidelines"
  510. .P
  511. The System Interfaces volume of POSIX.1\(hy2017,
  512. .IR "\fIrename\fR\^(\|)"
  513. .\"
  514. .SH COPYRIGHT
  515. Portions of this text are reprinted and reproduced in electronic form
  516. from IEEE Std 1003.1-2017, Standard for Information Technology
  517. -- Portable Operating System Interface (POSIX), The Open Group Base
  518. Specifications Issue 7, 2018 Edition,
  519. Copyright (C) 2018 by the Institute of
  520. Electrical and Electronics Engineers, Inc and The Open Group.
  521. In the event of any discrepancy between this version and the original IEEE and
  522. The Open Group Standard, the original IEEE and The Open Group Standard
  523. is the referee document. The original Standard can be obtained online at
  524. http://www.opengroup.org/unix/online.html .
  525. .PP
  526. Any typographical or formatting errors that appear
  527. in this page are most likely
  528. to have been introduced during the conversion of the source files to
  529. man page format. To report such errors, see
  530. https://www.kernel.org/doc/man-pages/reporting_bugs.html .