Managing files and directories is a fundamental task in Linux. The mv command lets you move directories efficiently using the terminal or GUI.
This guide covers both methods to move directories in Linux.
Prerequisites:
- A system running Linux
- Access to the terminal
- Basic command-line knowledge
How to Use mv Command to Move Directories
The mv command moves files and directories between locations. Use this syntax:
mv [options] [source] [destination]
Move the Projects directory to Documents:
mv Projects Documents
The command executes silently. No output means success.
Move multiple directories by listing them before the destination:
mv [source1] [source2] [source3] [destination]
Move three directories to Archive:
mv Projects Reports Notes Archive
mv renames the source to the destination name instead.
Rename a directory by providing a new name:
mv [old_name] [new_name]
Rename Projects to WorkFiles:
mv Projects WorkFiles
mv Command Options
The mv command accepts several options:
| Option | Purpose |
|---|---|
-b |
Create backup of destination files |
-f |
Force overwrite without prompts |
-i |
Ask before overwriting files |
-n |
Never overwrite existing files |
-u |
Update only newer files |
-v |
Show detailed output |
-t |
Specify target directory |
-S |
Set backup file suffix |
Create a backup before overwriting:
mv -b notes.txt Documents
The backup file adds a tilde suffix: notes.txt~.
Change the backup suffix:
mv --backup -S .bak notes.txt Documents
The backup becomes notes.txt.bak.
Request confirmation before replacing files:
mv -i data Documents
Type y to proceed or n to cancel.
View each action as it happens:
mv -v Projects Archive
Output shows: renamed 'Projects' -> 'Archive/Projects'
/dev/null deletes them permanently. Double-check paths before executing commands.
Force overwrite with -f. Prevent overwriting with -n. Update only newer content with -u.
-i and -v for safe, visible operations: mv -iv source destination
How to Move Directories Using GUI
Linux file managers provide graphical options. The process varies slightly by desktop environment but follows similar steps.
Method 1: Cut and Paste
Select the directory. Press Ctrl+X or right-click and choose Cut.
Navigate to the destination. Press Ctrl+V or right-click and select Paste.
The directory moves with all contents and subdirectories.
Method 2: Move To Option
Right-click the directory. Select Move to… from the menu.
Browse to the destination folder. Click Select to complete the move.
Popular file managers include Nautilus for GNOME, Dolphin for KDE, and Thunar for Xfce. Each offers similar functionality.
Conclusion
Moving directories in Linux works through command line or GUI. The mv command offers precise control and options. File managers provide intuitive visual methods.
Master both approaches for efficient file management. Choose the method that suits your workflow.
FAQs
Use the command mv source_directory destination_directory. The directory moves with all its contents to the new location without creating copies.
The source directory moves inside the existing destination directory. If a directory with the same name exists there, it may be overwritten or merged depending on options used.
Yes, list all source directories before the destination: mv dir1 dir2 dir3 destination. The last argument becomes the target location for all preceding directories.
Use mv -n source destination to skip existing files. Alternatively, use mv -i source destination to get confirmation prompts before overwriting any files.
Yes, the mv command preserves all file permissions, ownership, and timestamps. The directory structure and all attributes remain unchanged after moving to the new location.