Mv (Unix)
On Unix implementations derived from AT&T Unix, HistoryMultics provided a file move/rename command named OptionsMost implementations support:
These options are a part of X/Open Portability Guidelines, later the basis of POSIX and SUS. A POSIX-compliant implementation must support these.[7] Name clashingWhen a file is moved to a path that specifies an existing file, the existing file is clobbered by default. If the existing file is not writable but is in a directory that is writable, the command prompts the user to confirm overwrite (if run from a terminal), unless the Accidental overwriting can be prevented using the GNU implementation Ambiguity arises when a file is moved to a path that specifies an existing directory. By default, Moving versus copying and removingMoving files within the same file system is generally implemented more efficiently than copying the file and then removing the original. On platforms that do not support the Such an operation is significantly simpler and faster than a copy-and-move operation. The file's inode number (i-number) does not change. No permission is required to read the file since only cataloguing information is changed. Since the source and target directories are being modified, entries are being created within the target directory and erased from within the source directory, write permission in both directories is required. Moving files from one file system to another may fail entirely or may be automatically performed as an atomic copy-and-delete action; the actual details are dependent upon the implementation. Moving a directory from one parent to a different parent directory requires write permission in the directory being moved, in addition to permissions to modify the old and new parents. This is because the i-number for the directory entry ".." (an alias for the parent of a directory) changes as a result of the rename. ExamplesThe following renames file or directory foo to bar. This assumes that bar is not an existing directory beforehand. $ mv foo bar The following moves the file or directory foo into the existing subdirectory subdir so that the result is at path subdir/foo. $ mv foo subdir The following moves the file or directory foo into directory subdir with name bar so that the resulting is path subdir/bar. This assumes that subdir/bar is not an existing directory beforehand. $ mv foo subdir/bar The following moves two files/directories, foo and bar, to existing directory subdir. $ mv foo bar subdir Copy be.03 to the bes directory of the mounted volume bkup, then be.03 is removed. In this example, /mnt refers to the directory (the "mount point") over which a file system is mounted. $ mv be.03 /mnt/bkup/bes Same as above, except each file moved out of be.03 is removed individually instead of all being removed at once after the entire copying is finished. $ mv be.03/* /mnt/bkup/bes The following takes longer than expected if /var is on a different file system, as it frequently is, since files will be copied and removed. The shell expands $ mv /var/log/*z ~/logs See also
References
External linksThe Wikibook Guide to Unix has a page on the topic of: Commands/File System Utilities#mv
|