Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux mv command

Linux mv command

Linux Command Reference Linux Command Reference

The Linux mv (short for "move file") command is used to rename files or directories, or to move them to other locations.

Syntax



mv [options] source dest

mv [options] source... directory

Parameter Description:

mv parameter settings and results

Command format Run Results
mv source_file(文件) dest_file(文件)
Rename the source file source_file to the target file dest_file
mv source_file(文件) dest_directory(目录)
Move the file source_file into the target directory dest_directory
mv source_directory(目录) dest_directory(目录)
If the directory dest_directory already exists, move source_directory into it; if dest_directory does not exist, rename source_directory to dest_directory
mv source_directory(目录) dest_file(文件)
Error

Example

Rename the file aaa to bbb:

mv aaa bbb

Put the info directory into the logs directory. Note that if the logs directory does not exist, this command renames info to logs.



mv info/ logs 

Another example: move all files and directories under /usr/runoob a given directory to the current directory, using the following command:



$ mv /usr/runoob/*  . 

Linux Command Reference Linux Command Reference