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 :)
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.
“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.
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.
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.
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 {} \;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With