Nov. 30th, 2020

jbanana: Badly drawn banana (Default)
In bash, I want to delete a lot of files. Easy enough:
rm somepath/prefix*.txt
But I get "Argument list too long" because there are a *lot* of files. Well, I know I can use find like this:
find somepath -name "prefix*.txt" -exec rm '{}' \;
but that removes the files one at a time, and there are thousands of them so it's inefficient (and I'm impatient).

Solution:
find somepath -name "prefix*.txt" -print0 | xargs -0 rm
Nice - the output from find is collected up by xargs until it has a nice big list but not too big and then it executes rm on that list, and repeats until none left.

Now I can't see what was baffling me.

May 2025

M T W T F S S
   1234
5678 91011
12131415161718
19202122232425
262728293031 

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 22nd, 2025 02:51 am
Powered by Dreamwidth Studios