xargs no longer baffles me
Nov. 30th, 2020 11:37 am![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
In bash, I want to delete a lot of files. Easy enough:
Solution:
Now I can't see what was baffling me.
rm somepath/prefix*.txtBut 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 rmNice - 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.