How to move all files and folders from one directory to another directory in Linux

Execute this command in your Linux terminal (Change the directory path):

mv  -v /var/www/html/directory1* /var/www/html/directory2/

This command will move all the files and folders from directory1 folder to directory2 folder.


To move all files, but not folders:

If you are interested in moving all files (but not folders) from directory1 folder to directory2 folder, use this command

find /var/www/html/directory1/ -type f -print0 | xargs -0 mv -t /var/www/html/directory2/

To move only files from the directory1 folders, but not from sub-folders:

If you want to move all files from the directory1 folder, but not any files within folders in the directory1 folder, use this command:

find /var/www/html/directory1/ -maxdepth 1 -type f -print0 | xargs -0 mv -t /var/www/html/directory2/

here, -maxdepth option specifies how deep find should try, 1 means, only the directory specified in the find command. You can try using 23 also to test.

Scroll to Top