Linux Terminal Command: mv
The mv command is an essential tool in File Manipulation & Viewing. In this tutorial, we will explore what mv does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.
Concept & Explanation
The mv command moves files or folders to a new directory, or renames them if the source and destination are in the same folder. It is fast because it only updates directory pointer links rather than copying bytes.
Common Options & Syntax
mv [options] [arguments]
Here are the most common flags used with mv:
- Simple Usage: Basic default commands.
- Detailed View: Shows diagnostic information.
- Advanced Actions: Can chain parameters for scripting.
1. Interactive Example (Simple)
Here is how most people run the command:
# Example
mv old_name.txt new_name.txt
What it does: Renames ‘old_name.txt’ to ’new_name.txt’ in the current directory.
2. Power-User Example (Advanced)
For scripting and advanced diagnostics, use this configuration:
# Advanced
mv -u -i *.txt archive/
What it does: Moves all text files to the ‘archive’ folder, prompting before overwriting (-i) and only moving files that are newer than the files already in the target directory (-u).
⚙️ Warning & Common Pitfalls
[!WARNING] Moving a folder into a target folder that doesn’t exist will rename the source folder to the target name rather than placing it inside a new directory.
🔗 Related Commands
Here are some related posts on cli_tty1 you might want to check out: