Overview of mv
`mv` command is a primary means of moving data within the file system. Unlike copying (cp), it does not leave the original file behind; it changes the location or renames the file. When moving files within the same file system, it changes only the metadata (inode) without moving the actual data, making it very fast.
Key Roles of mv
`mv` command is primarily used for the following purposes:
Main Areas of Use
- Renaming Files: Changes the name of a file or its extension.
- Renaming Directories: Changes the name of a directory.
- Moving Files: Moves a file from one directory to another.
- Moving Directories: Moves a directory and all its contents to another location.
- Managing Backup Files: Used when moving an existing file to a backup and replacing it with a new file.
Key mv Command Options
`mv` command provides various options to prevent overwriting, force execution, and detailed output when moving/renaming files or directories.
1. Basic Move/Rename
2. Overwrite and Confirmation Options
3. Other Information Output Options
Generated command:
Try combining the commands.
Description:
`mv` Executes the command.
Combine the above options to virtually execute commands with AI.
Usage Examples
Learn how to effectively move and rename files and directories through various examples of the `mv` command.
Renaming a File
mv old_report.txt new_report.txt
Changes the name of the `old_report.txt` file to `new_report.txt`.
Moving a File to Another Directory
mv document.pdf /home/user/archives/
Moves the `document.pdf` file from the current directory to the `/home/user/archives/` directory.
Renaming a Directory
mv old_project_folder new_project_folder
Changes the name of the `old_project_folder` directory to `new_project_folder`.
Confirm Before Overwriting When Moving a File
sudo mv -i config.ini /etc/
When moving the `config.ini` file to `/etc/`, it asks whether to overwrite if a file with the same name already exists at the target location.
Moving Multiple Files to One Directory
mv image1.jpg image2.jpg image3.png photos/
Moves three files: `image1.jpg`, `image2.jpg`, and `image3.png` to the `photos` directory at once.
Verbose Output and Backup Creation When Moving a File
mv -vb main.log main.log.old
When moving the `main.log` file to `main.log.old`, if `main.log.old` already exists, it creates a backup and outputs the moving process in detail.