|
Post by dejohnny on Jun 1, 2012 15:52:33 GMT -5
I tried to delete more than 5500 Jpeg images from a folder and got this error.
Command:
rm *.jpg
STDOUT: error
-sh: /bin/rm: Argument list too long
|
|
|
Post by dejohnny on Jun 1, 2012 16:09:23 GMT -5
The workaround for the problem can be taken care of by a one-liner:
find . -name '[\w\d]+\.+[\w]{3}' | xargs rm -f -r
First, I've use the find function by passing it an argument specifying the directory and name of the file to match. Here I've passed it a dot(.) telling it to look in the current working directory, and a regular expression that matches the files to be found. Next, I've used the pipe expression to send the results of the last command to another command on the right side of the pipe. When the values pass through the pipe the command xargs takes the stream of data from the pipe and breaks the list of arguments into smaller sub lists that next command can handle. Finally, those smaller lists get sent to rm command so that it can delete the files that were found earlier.
|
|