Linux mv Command
The Linux mv (short for "move file") command is used to rename files or directories, or to move files or directories to another location.
Syntax
mv [options] source dest
mv [options] source... directory
Parameter Description:
--b: When the target file or directory exists, a backup of it will be created before overwriting.
--i: If the specified source directory or file has the same name as the target directory or file, it will ask before overwriting the old file. Enter 'y' to overwrite, and 'n' to cancel the operation.
--f: If the specified source directory or file has the same name as the target directory or file, it will overwrite the old file without asking.
--n: Do not overwrite any existing files or directories.
--u: Move only when the source file is newer than the destination file or when the destination file is missing.
mv Parameter Settings and Execution Results
Command Format | Execution Results |
---|---|
mv source_file(file) dest_file(file) | Rename source file source_file to dest_file |
mv source_file(file) dest_directory(directory) | Move file source_file to directory dest_directory |
mv source_directory(directory) dest_directory(directory) | If directory dest_directory exists, move source_directory into dest_directory; if it does not exist, rename source_directory to dest_directory |
mv source_directory(directory) dest_file(file) | Error |
Examples
Rename file aaa to bbb:
mv aaa bbb
Move the info directory into the logs directory. Note that if the logs directory does not exist, this command will rename info to logs.
mv info/ logs
For example, to move all files and directories from /usr/tutorialpro to the current directory, the command is:
$ mv /usr/tutorialpro/* .