Linux mv Command

Linux 命令大全Linux Command Encyclopedia

The Linux mv (English full spelling: move file) command is used to rename files or directories, or move files or directories to other locations.

Syntax

mv [options] source dest
mv [options] source... directory

Parameter Description:

  • -b: When the target file or directory exists, a backup 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 first ask whether to overwrite the old file. Enter y to overwrite directly, enter 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 not ask and will directly overwrite the old file.
  • -n: Do not overwrite any existing files or directories.
  • -u: Only perform the move operation when the source file is newer than the target file or the target file does not exist.

mv Parameter Settings and Running Results

Command FormatRunning Result
mv source_file(文件) dest_file(文件)
Change the source file name source_file to the destination file name dest_file
mv source_file(文件) dest_directory(目录)
Move the file source_file to the destination directory dest_directory
mv source_directory(目录) dest_directory(目录)
If the destination directory dest_directory already exists, move source_directory into dest_directory; if dest_directory does not exist, rename source_directory to dest_directory
mv source_directory(目录) dest_file(文件)
Error

Examples

Rename file aaa to bbb:

mv aaa bbb

Put the info directory into the logs directory. Note: if the logs directory does not exist, this command will rename info to logs.

mv info/ logs 

Another example: move/usr/exampleall files and directories under it to the current directory, the command line is:

$ mv /usr/example/*  . 

Linux 命令大全Linux Command Encyclopedia

Other Extensions