Understanding the mv Command

Basic Usage of mv

The mv command is used to move or rename files and directories in Linux. It can either move a file to a different location or rename the file in the same directory:

mv [source] [destination]

If the destination is a directory, it will move the source file there. If the destination is a file, the source file will be renamed to the destination.

Options Available with mv

mv -i (Interactive Mode)

Prompts before overwriting an existing file:

mv -i file1.txt /home/user/directory/

This will ask for confirmation before overwriting file1.txt if it already exists in the destination.

mv -f (Force Overwrite)

Forces overwriting of the destination file without asking for confirmation:

mv -f file1.txt /home/user/directory/

mv -n (No Overwrite)

Does not overwrite an existing file in the destination:

mv -n file1.txt /home/user/directory/

If file1.txt already exists in the destination directory, it will not be overwritten.

mv -v (Verbose Output)

Displays detailed information about the moving or renaming process:

mv -v file1.txt /home/user/directory/

This shows exactly what is happening during the mv process, which is useful for tracking large batch operations.

mv --help

Displays help information for the mv command:

mv --help

Summary of Options

Option Description
mv [source] [destination] Move or rename a file or directory.
mv -i [file] Interactive mode, asks before overwriting files.
mv -f [file] Force overwriting of files without confirmation.
mv -n [file] No overwriting of existing files.
mv -v [file] Verbose mode, displays detailed information during the move process.
mv --help Display help information for the mv command.

Manual Pages

For more detailed information, use the manual page for the mv command:

man mv