This guide will show you how to move files from one directory to another using the mv
command on the command line. This applies to most Linux distributions including AlmaLinux, CentOS, Ubuntu, and Debian.
๐ Basic Syntax
mv [options] source destination
โ Move All Files from One Directory to Another
Example:
Move all files from /home/user/source/
to /home/user/destination/
:
mv /home/user/source/* /home/user/destination/
โ This will move all files (but not hidden files or subdirectories).
โ
Include Hidden Files (Files Starting with .
)
mv /home/user/source/.* /home/user/source/* /home/user/destination/
Or more safely using a subshell to avoid errors with .
and ..
:
shopt -s dotglob
mv /home/user/source/* /home/user/destination/
shopt -u dotglob
โ Move Files Recursively (Including Subdirectories)
To move all contents, including subfolders and hidden files:
mv /home/user/source/. /home/user/destination/
Note the use of
/.
which ensures that everything (including hidden files and directories) is moved.
๐ If You Encounter “Permission Denied”
Use sudo
:
sudo mv /home/user/source/* /home/user/destination/
โ ๏ธ Overwriting Files Without Prompt
By default, mv
overwrites without asking. To force interactive mode (prompt before overwriting):
mv -i /home/user/source/* /home/user/destination/
Or to force overwriting without confirmation:
mv -f /home/user/source/* /home/user/destination/
โ Check if Files Moved Correctly
After moving, you can check with:
ls /home/user/destination/
๐งผ Optional: Delete the Source Directory After Moving
rm -r /home/user/source/
Only do this if you’re sure the move was successful.