|The Wikibook Guide to Unix has a page on the topic of: Commands/File System Utilities#mv|
mv (short for move) 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 the file will move between. This is because mv changes the file's location by editing the file list of each directory.
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 used
Usually moving files within the same file system 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.
Most versions Single Unix Specification#1980s: Motivation of mv support:
Additional options (Use man mv for details):
mv myfile mynewfilename # renames 'myfile' to 'mynewfilename'. mv myfile ~/myfile # moves 'myfile' from the current directory to user's home directory. mv myfile subdir/myfile # moves 'myfile' to 'subdir/myfile' relative to the current directory. mv myfile subdir # same as the previous command, filename is implied to be the same. mv myfile subdir/myfile2 # moves 'myfile' to 'subdir' named 'myfile2'. mv be.03 /mnt/bkup/bes # copies 'be.03' to the mounted volume 'bkup' the 'bes' directory, # then 'be.03' is removed. mv afile another /home/yourdir/yourfile mydir # moves multiple files to directory 'mydir'. mv -v Jun* bkup/06 # displays each filename as it is moved to the subdirectory 'bkup/06'. mv /var/log/*z ~/logs # takes longer than expected if '/var' is on a different file system, # as it frequently is, since files will be copied & deleted. mv --help # shows a concise help about the syntax of the command. mv !(bkup) bkup # mv all files and dirs to the dir in the same level # move "all the files and directories"(except bkup) to the "bkup" directory, # (assuming , if "all the files and directories" and "bkup" directory are in the same directory ) mv !(bkup1|bkup2) bkup2 # move "all the files and directories"(except bkup1, bkup2) to the "bkup2" directory. man mv # displays complete manual for mv.
This entry is from Wikipedia, the leading user-contributed encyclopedia. It may not have been reviewed by professional editors (see full disclaimer)