mv
is a mv
requires the user to have write permission for the ''directories'' the file will move between. This is because mv
changes the content of both directories (''i.e.'', the source and the target) involved in the move. When using the mv
command on files located on the same filesystem, the file's timestamp is not updated.
On UNIX implementations derived from argv
In computer programming, an entry point is the place in a program where the execution of a program begins, and where the program has access to command line arguments.
To start a program's execution, the loader or operating system passes contro ...
/code>. This is a common technique by which closely related commands that have been packaged as a unit allow the user to specify the particular course of the intended action.
History
A command that moves a directory entry to a new directory was first implemented within Multics
Multics ("Multiplexed Information and Computing Service") is an influential early time-sharing operating system based on the concept of a single-level memory.Dennis M. Ritchie, "The Evolution of the Unix Time-sharing System", Communications of t ...
. It can be contracted to . Later, the command appeared in Version 1 Unix
The term "Research Unix" refers to early versions of the Unix operating system for DEC PDP-7, PDP-11, VAX and Interdata 7/32 and 8/32 computers, developed in the Bell Labs Computing Sciences Research Center (CSRC).
History
The term ''Resear ...
and became part of the X/Open Portability Guide X/Open group (also known as the Open Group for Unix Systems and incorporated in 1987 as X/Open Company, Ltd.) was a consortium founded by several European UNIX systems manufacturers in 1984 to identify and promote open standards in the field of in ...
issue 2 of 1987.
The version of mv
bundled in GNU
GNU () is an extensive collection of free software (383 packages as of January 2022), which can be used as an operating system or can be used in parts with other operating systems. The use of the completed GNU tools led to the family of operat ...
coreutils
The GNU Core Utilities or coreutils is a package of GNU software containing implementations for many of the basic tools, such as cat, ls, and rm, which are used on Unix-like operating systems.
In September 2002, the ''GNU coreutils'' were cr ...
was written by Mike Parker, David MacKenzie, and Jim Meyering. The command is available as a separate package for Microsoft Windows
Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for serv ...
as part of the UnxUtils
UnxUtils is a collection of ports of common GNU Unix-like utilities to native Win32, with executables only depending on the Microsoft C- runtime msvcrt.dll. The collection was last updated externally on April 15, 2003, by Karl M. Syring. The mo ...
collection of native
Native may refer to:
People
* Jus soli, citizenship by right of birth
* Indigenous peoples, peoples with a set of specific rights based on their historical ties to a particular territory
** Native Americans (disambiguation)
In arts and entert ...
Win32
The Windows API, informally WinAPI, is Microsoft's core set of application programming interfaces (APIs) available in the Microsoft Windows operating systems. The name Windows API collectively refers to several different platform implementations th ...
ports
A port is a maritime facility comprising one or more wharves or loading areas, where ships load and discharge cargo and passengers. Although usually situated on a sea coast or estuary, ports can also be found far inland, such as H ...
of common GNU Unix-like utilities. The command has also been ported to the IBM i
IBM i (the ''i'' standing for ''integrated'') is an operating system developed by IBM for IBM Power Systems. It was originally released in 1988 as OS/400, as the sole operating system of the IBM AS/400 line of systems. It was renamed to i5/OS in ...
operating system.
Conflicting existing file
When a filename is moved to an existing filename, the existing file is deleted ( clobbered) by default. If the existing file is not writable but is in a directory that is writable, the mv command asks for confirmation (if run from a terminal) before proceeding, unless the -f (force) option is used.
Accidental overwriting can be prevented using the GNU -n
(long format: --no-clobber
) flag. Alternatively, -u
(--update
) only overwrites destination files that are older than source files, -i
(--interactive
) asks for confirmation upon each name conflict, and -b
(--backup
) renames target files out of the way.
A related ambiguity arises when a filename is moved to an existing directory. By default, mv
would handle this as one trying to move a name inside this directory. GNU mv has a switch for disabling this assumption and try to overwrite the directory instead. An inverse makes the move-to-directory operation explicit.
Moving versus copying and removing
Moving files ''within the same file system
In computing, file system or filesystem (often abbreviated to fs) is a method and data structure that the operating system uses to control how data is stored and retrieved. Without a file system, data placed in a storage medium would be one larg ...
'' is generally implemented differently than copying the file and then removing the original. On platforms that do not support the rename
Rename may refer to:
* Rename (computing), rename of a file on a computer
* RENAME (command), command to rename a file in various operating systems
* Rename (relational algebra)
In relational algebra, a rename is a unary operation written as \r ...
syscall, a new link is added to the new directory and the original one is deleted. The data of the file is not accessed. All POSIX
The Portable Operating System Interface (POSIX) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines both the system- and user-level application programming interf ...
-conformant systems implement the ''rename'' call.
An actual move (effectively a rename) is dramatically faster than the circuitous copy-and-move procedure. The file's i-number (short for "inode
The inode (index node) is a data structure in a Unix-style file system that describes a file-system object such as a file or a directory. Each inode stores the attributes and disk block locations of the object's data. File-system object attribute ...
number") does not change. No permission is required to read the file being moved insofar as—conceptually speaking—it is only information that is being changed as a result of the "move." Since the source and target directories are being modified, to wit, entries are being created within the target directory and erased from within the source directory, "write" permission in both directories is required to complete the move. 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 ".." (which can be used in any context as an alias for the parent of the current directory) changes as a result of the rename.
Options
Most versions of mv support:
* -i
interactively process, write a prompt to standard error
The standard error (SE) of a statistic (usually an estimate of a parameter) is the standard deviation of its sampling distribution or an estimate of that standard deviation. If the statistic is the sample mean, it is called the standard error ...
before moving a file that would overwrite an existing file. If the response from the standard input begins with the character 'y' or 'Y', the move is attempted. (Overrides previous -f option.)
* -f
force overwriting the destination (overrides previous -i option).
These options are a part of X/Open Portability Guidelines, later the basis of POSIX and SUS. All POSIX-compliant mv implementations must support these. Single Unix Specification#1980s: Motivation
Examples
Note that, in the above example, ''/mnt'' referred to the directory (the "mount point") over which a given file system is mounted. Naming such directories ''/mnt'' is a popular convention but is by no means necessary. A "file system" can be thought of as an independent tree that is logically regarded as a unit; its root is "mounted" atop a directory of the administrator's choice. Any previous contents of that directory are invisible, but they are "restored" when the new volume is unmounted.
See also
*cp (Unix)
In computing, cp is a command in various Unix and Unix-like operating systems for copying files and directories. The command has three principal modes of operation, expressed by the types of arguments presented to the program for copying a file ...
*ln (Unix)
The command is a standard Unix command utility used to create a hard link or a symbolic link (symlink) to an existing file or directory. The use of a hard link allows multiple filenames to be associated with the same file since a hard link po ...
*rm (Unix)
rm (short for ''remove'') is a basic command on Unix and Unix-like operating systems used to remove objects such as computer files, directories and symbolic links from file systems and also special files such as device nodes, pipes and sockets, ...
*List of Unix commands
This is a list of Unix commands as specified by IEEE Std 1003.1-2008, which is part of the Single UNIX Specification (SUS). These commands can be found on Unix operating systems and most Unix-like operating systems.
List
See also
* List of G ...
*move (command)
In computing, move is a command in various command-line interpreters ( shells) such as COMMAND.COM, cmd.exe, 4DOS/ 4NT, and PowerShell. It is used to move one or more files or directories from one place to another. The original file is deleted, ...
*ren (command)
In computing, ren (or rename) is a command in various command-line interpreters ( shells) such as COMMAND.COM, cmd.exe, 4DOS, 4NT and Windows PowerShell. It is used to rename computer files and in some implementations (such as AmigaDOS) also d ...
References
External links
*
*
{{Core Utilities commands
Unix SUS2008 utilities
Inferno (operating system) commands
IBM i Qshell commands