English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Linux mv Command

Linux Command大全

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

Syntax

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

Parameter Description:

  • -bWhen the target file or directory exists, a backup will be created for it before the overwrite operation is performed.
  • -iIf the specified source directory or file has the same name as the target directory or file, an inquiry will be made first to determine whether to overwrite the old file. Input y to overwrite directly, and input n to cancel the operation.
  • -fIf the specified source directory or file has the same name as the target directory or file, the old file will be overwritten directly without any inquiry.
  • -nDo not overwrite any existing files or directories.
  • -uWhen the source file is newer than the target file or the target file does not exist, the move operation is executed.

mv Parameter Settings and Running Results

Command Format Running Results
mv source_file(file) dest_file(file)
Rename the source file name source_file to the target file name dest_file
mv source_file(file) dest_directory(directory)
Move the file source_file to the target directory dest_directory
mv source_directory(directory) dest_directory(directory)
If the directory name dest_directory already exists, move source_directory to the directory name dest_directory; if the directory name dest_directory does not exist, rename source_directory to the directory name dest_directory
mv source_directory(directory) dest_file(file)
Error

Online 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, the command will rename info to logs.

mv info/ logs 

For example, to move /usr/w3codebox Move all files and directories under to the current directory, the command line is:

$ mv /usr/w3codebox/*  . 

Linux Command大全