Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Mv (Unix)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Shell command for moving files}} {{Lowercase title}} {{Infobox software | name = mv | author = [[Ken Thompson]], [[Dennis Ritchie]]<br />([[AT&T Bell Laboratories]]) | developer = Various [[open-source software|open-source]] and [[commercial software|commercial]] developers | released = {{Start date and age|1971|11|3}} | latest release version = | latest release date = | operating system = [[Unix]], [[Unix-like]], [[Inferno (operating system)|Inferno]], [[IBM i]] | platform = [[Cross-platform]] | genre = [[Command (computing)|Command]] | license = [[coreutils]]: [[GPLv3]] | website = }} <code>'''mv'''</code> is a [[shell (computing)|shell]] [[command (computing)|command]] for renaming and moving [[computer file|files]] and [[directory (computing)|directories]]. If both items are on the same [[file system]], the command renames; otherwise items are copied to the destination and the old items are removed (more specifically [[unlink (Unix)|unlinked]]). To move between two directories, the user must have write permission for both because the command modifies the content of both. For a rename, an item's timestamp is not modified. On [[Unix]] implementations derived from [[AT&T Unix]], <code>[[cp (Unix)|cp]]</code>, <code>[[ln (Unix)|ln]]</code> and <code>mv</code> are implemented as a single program with [[hard-linked]] binaries. ==History== [[Multics]] provided a file move/rename command named {{code|move}}. A version with the contracted name {{code|mv}}<ref>[https://www.multicians.org/multics-commands.html Multics Commands]</ref> appeared in [[Ancient Unix|Version 1 Unix]]<ref>{{man|1|mv|FreeBSD}}</ref> and became part of the [[X/Open Portability Guide]] issue 2 of 1987.<ref>{{man|cu|mv|SUS|move files}}</ref> The version in [[GNU Core Utilities]] was written by Mike Parker, David MacKenzie, and Jim Meyering.<ref name=gnu/> The command is available in [[Windows]] via [[UnxUtils]].<ref>{{Cite web|url=http://unxutils.sourceforge.net/|title=Native Win32 ports of some GNU utilities|website=unxutils.sourceforge.net}}</ref> The command was ported to [[IBM i]].<ref>{{cite web |title=IBM System i Version 7.2 Programming Qshell |language=en |author=IBM |website=[[IBM]] |author-link=IBM |url=https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzahz/rzahzpdf.pdf?view=kc |access-date=2020-09-05 }}</ref> ==Options== Most implementations support: * <code>-i</code> '''i'''nteractive; the command prompts the user to confirm moving each file that would overwrite an existing file; overrides a preceding {{code|-f}} option * <code>-f</code> '''f'''orce overwriting existing files; overrides a preceding {{code|-i}} option These options are a part of X/Open Portability Guidelines, later the basis of POSIX and [[Single UNIX Specification|SUS]]. A POSIX-compliant implementation must support these.<ref>[[Single Unix Specification#1980s: Motivation]]</ref> ==Name clashing== When a file is moved to a path that specifies an existing file, the existing file is [[clobbering|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 {{code|-f}} option is included. Accidental overwriting can be prevented using the GNU implementation <code>-n</code> (long format: <code>--no-clobber</code>) option. Alternatively, <code>-u</code> (<code>--update</code>) only overwrites destination files that are older than source files, <code>-i</code> (<code>--interactive</code>) asks for confirmation upon each name conflict, and <code>-b</code> (<code>--backup</code>) renames target files to prevent overwrite. Ambiguity arises when a file is moved to a path that specifies an existing directory. By default, <code>mv</code> handles this by moving the file inside the directory. The GNU implementation has a {{code|-T}} switch for that tries to overwrite the directory instead. An inverse {{code|-t}} makes the move-to-directory operation explicit.<ref name=gnu>{{man|1|mv|ManKier}}</ref> ==Moving versus copying and removing== Moving 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 <code>[[rename (computing)|rename()]]</code> [[system call]], a new [[hard link]] is added to the new directory and the original one is deleted. The data of the file is not accessed. A [[POSIX]]-conformant system implements {{code|rename()}}. 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. ==Examples== The 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 [[Mount (computing)|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 <code>~</code> to the user's [[home directory]] and treats <code>*</code> as a [[wildcard character]]. $ mv /var/log/*z ~/logs ==See also== * {{Annotated link|cp (Unix)}} * {{Annotated link|List of POSIX commands}} * {{Annotated link|ln (Unix)}} * {{Annotated link|move (command)}} * {{Annotated link|ren (command)}} * {{Annotated link|rm (Unix)}} ==References== {{Reflist}} ==External links== {{Wikibooks|Guide to Unix|Commands/File System Utilities#mv}} *{{man|1|mv|SUS}} *{{man|1|mv|Inferno}} {{Unix commands}} {{Core Utilities commands}} [[Category:Unix SUS2008 utilities]] [[Category:Inferno (operating system) commands]] [[Category:IBM i Qshell commands]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Annotated link
(
edit
)
Template:Cite web
(
edit
)
Template:Code
(
edit
)
Template:Core Utilities commands
(
edit
)
Template:Infobox software
(
edit
)
Template:Lowercase title
(
edit
)
Template:Man
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Sister project
(
edit
)
Template:Unix commands
(
edit
)
Template:Wikibooks
(
edit
)