/bin/rm: Argument list too long (find's delete flag!)

R

Rob

Guest
At some point in your Linux life you'll come across a directory of session files (or something similar) that you want to remove. BUT, when you try to remove the files with linux's rm command you're met with the error message:

/bin/rm: Argument list too long


Fret not.. use find to remove these session files with it's -delete flag!

Let's say we're looking to delete files named session_848938, session_45949343, session_454344, etc.. and they live in /path/to/files/

[xcode=bash]find /path/to/files/ -name "session_*" -delete[/xcode]

Before I found out about find's cool -delete flag I'd pair up find with exec or xargs..

[xcode=bash]find /path/to/files/ -name "session_*" -exec rm {} \;
find /path/to/files/ -name "session_*" -print0 | xargs -0 rm[/xcode]

Now, however.. i'll use the -delete flag.

Does anyone know how long it's been around?
 


I don't know how long it's been around, but on my Ubuntu 8.10 the delete flag is listed in the man page, but it doesn't work. I get this message:

find: invalid predicate `-delete'
 
8.10 is fairly old. Ubuntu 12.10 will be out in a few months. 8.10 is nearly 4 years old. Have you considered upgrading?
 

Staff online

Members online


Top