The mv command in Linux is used to move files and directories from one location to another. It can also be used to rename files and directories. The basic syntax of the mv command is:
mv [OPTIONS] source destination
Key Functions:
-
Move Files: You can move a file from one directory to another.
mv source_file.txt /path/to/destination/ -
Rename Files: You can rename a file by specifying a new name in the destination.
mv oldname.txt newname.txt -
Move and Rename: You can move a file to a new directory and rename it in one command.
mv file.txt /path/to/destination/newname.txt
Common Options:
-i: Prompts before overwriting an existing file.-u: Moves the file only if the source file is newer than the destination file or if the destination file does not exist.-v: Verbose mode; shows what is being done.
Example:
To move a file named example.txt from the current directory to a directory named backup, you would use:
mv example.txt backup/
The mv command is a fundamental tool for file management in Linux and is essential for organizing files and directories effectively.
