Last Updated: February 25, 2016
·
742
· james2doyle

Delete All Files in A dir function

Made this initially to remove all .DS_Store files in a directory. Now it is it's own function! Just pass the target and watch it be rm'd!!

removeall () {
    find . -name $1 -print0 | xargs -0 rm -v
}

How to use this

removeall .DS_Store

or

removeall '*.cache'

What the function does
this func will recursively remove all .DSStore files in the current directory. I will step through the code:
* find the file
* that matches the name $1 (name in the argument ex: *.DS
Store*)
* run a command on each result
* remove the file
* print out what was done

To use this just add it to your ~/.bashrc

Or if you are cool, your ~/.zshrc file.

modified from this post at binary age