How to use locate with xargs
Many are aware of how to use find with xargs. For example, to remove those annoying .DS_Store files OS X leaves everywhere you can do:
find . -name .DS_Store -print0 | xargs -0 print rm -f
The key here is -print0 and -0 tells find and xargs to use the ascii null character instead of spaces. Recently I learned how to do something similar with locate as that command doesn’t have a -print0 option.
locate 'what_you_are_looking_for' -0 | xargs -0 rm -f
The -0 in the locate is equivalent to the -print0 in find.
One Comment
→

Thanks for posting this.
I have a file server littered with PP11Thumbs.ptn files that needed attention. I think I’ll remove the .DS_Store files while I’m at it.