← 返回命令列表

Linux command

mv 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Move a file to a directory

mv [source] [directory/]

Rename a file

mv [oldname.txt] [newname.txt]

Move multiple files to a directory

mv [file1] [file2] [directory/]

Move with confirmation before overwrite

mv -i [source] [destination]

Don't overwrite existing files

mv -n [source] [destination]

Move and show what's being done

mv -v [source] [destination]

Move with backup of existing destination

mv --backup=numbered [source] [destination]

说明

mv moves and renames files and directories. When the source and destination are on the same filesystem, it performs an atomic rename. When moving across filesystems, it copies the data and then removes the original. Renaming is simply moving a file within the same directory. Moving a file into a directory places it inside that directory with the same basename. If multiple sources are given, the last argument must be a directory and all sources are moved into it.

参数

-i, --interactive
Prompt before overwriting an existing file.
-f, --force
Do not prompt before overwriting. Overrides -i and -n.
-n, --no-clobber
Do not overwrite an existing file. Overrides -i and -f.
-v, --verbose
Print the name of each file being moved.
-u, --update
Move only when the source is newer than the destination or the destination does not exist.
--backup=_CONTROL_
Make a backup of each existing destination file. CONTROL can be numbered, existing, simple, or none.
-S, --suffix _SUFFIX_
Override the usual backup suffix (default ~).
-t, --target-directory _DIRECTORY_
Move all sources into the specified directory.
-T, --no-target-directory
Treat destination as a normal file, not a directory.

FAQ

What is the mv command used for?

mv moves and renames files and directories. When the source and destination are on the same filesystem, it performs an atomic rename. When moving across filesystems, it copies the data and then removes the original. Renaming is simply moving a file within the same directory. Moving a file into a directory places it inside that directory with the same basename. If multiple sources are given, the last argument must be a directory and all sources are moved into it.

How do I run a basic mv example?

Run `mv [source] [directory/]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -i, --interactive do in mv?

Prompt before overwriting an existing file.