Mv
Encyclopedia
mv is a Unix
command that moves one or more files
or directories
from one place to another. Since it can "move" files from one filename to another, it is also used to rename files. Using mv requires the user to have write permission for the directories which the file will move between. This is because mv changes the file's location by editing the file list of each directory.
is not the same as copying and then removing the original. First a new link is added to the new directory then the original link is deleted. The data of file is not accessed. This is much faster than physical copy and remove the file-content. The file still has the same inode.
When moving files to a different file system
, all files are copied and then all files are removed. If the copy fails (as in not enough space) none of the original files are removed and all of the copied files remain (and the volume remains full!). If the files are on one volume, an out of space condition cannot occur.
You cannot copy a file if you do not have read permissions, but you can move it if you have write permission to its old and new directories.
If you do not have write permission to a non-empty directory, you cannot delete this directory (since you cannot delete its contents); but you can move it.
Additional options (Use man mv for details):
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...
command that moves one or more files
Computer file
A computer file is a block of arbitrary information, or resource for storing information, which is available to a computer program and is usually based on some kind of durable storage. A file is durable in the sense that it remains available for programs to use after the current program has finished...
or directories
Directory (file systems)
In computing, a folder, directory, catalog, or drawer, is a virtual container originally derived from an earlier Object-oriented programming concept by the same name within a digital file system, in which groups of computer files and other folders can be kept and organized.A typical file system may...
from one place to another. Since it can "move" files from one filename to another, it is also used to rename files. Using mv requires the user to have write permission for the directories which the file will move between. This is because mv changes the file's location by editing the file list of each directory.
Conflicting existing file
When a filename is moved to an existing filename (in the same directory), the existing file is deleted. 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 usedmove versus copy and remove
Usually moving files within the same file systemFile system
A file system is a means to organize data expected to be retained after a program terminates by providing procedures to store, retrieve and update data, as well as manage the available space on the device which contain it. A file system organizes data in an efficient manner and is tuned to the...
is not the same as copying and then removing the original. First a new link is added to the new directory then the original link is deleted. The data of file is not accessed. This is much faster than physical copy and remove the file-content. The file still has the same inode.
When moving files to a different file system
File system
A file system is a means to organize data expected to be retained after a program terminates by providing procedures to store, retrieve and update data, as well as manage the available space on the device which contain it. A file system organizes data in an efficient manner and is tuned to the...
, all files are copied and then all files are removed. If the copy fails (as in not enough space) none of the original files are removed and all of the copied files remain (and the volume remains full!). If the files are on one volume, an out of space condition cannot occur.
You cannot copy a file if you do not have read permissions, but you can move it if you have write permission to its old and new directories.
If you do not have write permission to a non-empty directory, you cannot delete this directory (since you cannot delete its contents); but you can move it.
Options
Most versions Single Unix Specification#1980s: Motivation of mv support:- -h help by displaying additional options supported. Use man mv for details for the version on the system you are using.
- -i interactively process, write a prompt to 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 or -n options.)
- -n no overwriting of existing files. (overrides previous -f or -i options.)
- -f force overwriting the destination (overrides previous -i or -n options).
- -v verbose, shows filenames/directory names after they are moved.
Additional options (Use man mv for details):
- -u update only when the original is newer than the destination or when the destination doesn't exist.
- -b backup of existing destination using default ~ suffix.
Examples
See also
- cpCp (Unix)cp is a UNIX command used to copy a file. Files can be copied either to the same directory or to a completely different directory, possibly on a different file system or hard disk drive. If the file is copied to the same directory, the new file must have a different name to the original; in all...
- lnLn (Unix)ln is a standard Unix command used to create links to files.- Link files :Links allow more than one file name to refer to the same file, elsewhere.There are two types of links, both of which are created by ln:...
- rmRm (Unix)rm is a basic UNIX command used to remove objects such as files, directories, device nodes, symbolic links, and so on from the filesystem...
- List of Unix programs
- move (command)Move (command)In computing, move is a command in various DOS, OS/2 and Microsoft Windows command line interpreters such as COMMAND.COM, cmd.exe, 4DOS/4NT and Windows PowerShell. It is used to move one or more files or directories from one place to another. The original file is deleted, and the new file may have...
- ren (command)Ren (command)In computing, ren is a command in various DOS, OS/2 and Microsoft Windows command line interpreters such as COMMAND.COM, cmd.exe, 4DOS/4NT and Windows PowerShell. It is used to rename files and in some implementations also directories. It is analogous to the Unix mv command...