๐Ÿงพ How to Move All Files from One Folder to Another via Command Line

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.

Scroll to Top