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?
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.
Short Summary:
There are multiple options:
will call
rm
once for every filewill call
rm
only as often as necessary by constructing a command line that uses the maximum length possiblesame as above, you may (or rather will, as above - which was my approach) run into problems with filenames that contain characters that need quoting
is probably the best solution Please Upvote Dan C's comment it's his solution. It will as the earlier snippet call
rm
only as often as need by constructing a command line that uses the maximum lenght possible, the-0
switch means that arguments to therm
command will be separated by\0
so that escaping is done right in the shell.On a side note about the comment to restrict by using
-type f
you can also restrict with-size 0
(exactly 0 bytes) I can't verify if CakePHP really adheres to that convention but just about every project I know that uses placeholder files to check empty directories into the source repositories does that.Also as Matt Simons points out adding a
-v
flag might be a nice option to see some progress, however do notice that this will definitely slow down the whole process. A better approach might be to follow the process by usingstrace -p $pid_of_xargs
(add addtional options if you want to follow child processes, afaik that is possible)Another note i just found in the manpage:
after all find has all of that builtin :)
A possible reason why cakePHP might do this is because some version control systems (e.g. Mercurial and Git) cannot track an empty directories.
This might do:
Find recurses by default.