Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I move many files without having Argument list too long?

I am trying to move about 700,000 .jpg files from one directory to another in my Ubuntu server. I tried the following:

xargs mv *  -t /var/www/html/

and

echo (*.jpg|*.png|*.bmp) | xargs mv -t /var/www/html/

and

echo (*.jpg) | xargs mv -t /var/www/html/

and

find . -name "*.jpg" -print0 | xargs mv * ../

and they all give me the same error: /usr/bin/xargs: Argument list too long

what should I do? Please help me out. Thanks :)

like image 621
Awah Hammad Avatar asked Jan 09 '16 12:01

Awah Hammad


People also ask

How do you fix arguments too long?

If there are a large number of files in a single directory, Then the traditional rm command can not delete all files and ends with an error message Argument list too long . To resolve this issue and delete all files use xargs command-line utility with the find command.

What does argument list too long mean?

“Argument list too long” indicates when a user feeds too many arguments into a single command which hits the ARG_MAX limit. The ARG_MAX defines the maximum length of arguments to the exec function.

How do I move too many files in Linux?

To move files from one directory to another, the 'mv' command is used in Linux. This command is available in Linux by default and can be used to move files as well as directories.

How do you grep an argument list too long?

You can use the -n option of xargs to limit the number of arguments. But a better solution is to use -type f instead of -name "*" in order to limit the list to ordinary files, avoiding the error message for each folder.


1 Answers

If you use find I would recommend you to use the -exec attribute. So your result should be find . -name "*.jpg" -exec mv {} /home/new/location \;.

However I would recommend to check what the find command returns you, replacing the exec part with: -exec ls -lrt {} \;

like image 196
Jeffrey Descan Avatar answered Sep 17 '22 10:09

Jeffrey Descan