Linux – Remove all files by filename (Linux one-liner)

cakephplinuxscripting

CakePHP has a convention of putting files called "empty" in empty directories. I'm sure they have a reason, but it really bugs me. (Yeah, OCD, I know…)

I want a one-line linux shell command that will delete every file with the name "empty" in every descendent directory. (I suppose it would be useful to be able to specify wildcards for more general use too.)

Any ideas?

Best Answer

Simplest is:

find . -name empty -type f -exec rm -f {} \;

"." starts at current directory, replace with a directory path if you want to execute it in another location.

"-type f" just makes sure it's a file.

Related Topic