GO KALI FREE
File Management

mv Linux Command

Moves or renames files and directories.

What does mv do?

Moves or renames files and directories.

Syntax

mv [options] source destination

Practical example

mv oldname.txt newname.txt

Questions about mv

How do I rename a file with mv?

Use `mv oldname.txt newname.txt` to rename a file. The file content remains unchanged, only the name changes.

How do I move a file to a different directory?

Use `mv file.txt /destination/` to move a file. The file is removed from the original location after moving.

How do I move multiple files at once?

Use `mv file1 file2 file3 /destination/` or `mv *.txt /destination/` to move multiple files in a single command.

How do I move files without overwriting?

Use `mv -i` to prompt before overwriting, or `mv -n` to never overwrite existing files at the destination.

How do I move a directory with mv?

Use `mv source_dir dest_dir` to move a directory. Unlike cp, you do not need the `-r` flag with mv.

What does mv -v do?

The `-v` (verbose) flag displays each file as it is moved, which is helpful for tracking operations in scripts or large moves.

How do I move a file and rename it at the same time?

Specify the full destination path with the new name: `mv file.txt /new/path/renamed.txt`.

Related File Management

cp

Copies files or directories from one location to another.

rm

Removes (deletes) files or directories. Use -rf for recursive force delete.

touch

Creates an empty file or updates the timestamp of an existing file.

rmdir

Removes an empty directory. Safer than rm -r for removing directories.

mkdir

Creates a new directory (folder). Use -p to create nested directories.

cat

Displays the entire contents of a file on the terminal.