As the title states, I'm trying to recursively delete all files in a folder that begin with ._
. For each file on my site, there exists a file with the same exact name, but with ._
appended to it. How do I get rid of these pesky buggers? Thanks!
views:
74answers:
2I think you meant "prepended"
LATER EDIT
SH script:
The previous code didn't work recursively; this one does.
If you want to delete folders too, use this:
find . -name ".?*" -exec rm {} \;
find . -name ".?*" -exec rm -R {} \;
Edit: User Gilles below correctly mentions that the following alternative technique can be dangerous because xargs doesn't treat single and double quotes in a filename literally. A file with a name of Today's special.txt
would cause an error (unterminated quotes). I still include it here for sake of completeness, since it is widely mentioned on the web.
Another similar way of doings this on Unix/Mac by piping to rm.
find . -name '.*' -type f | xargs rm -f
The -type f
argument tells it to ignores directories and special files like ., .., symbolic links and devs.
We unfortunately can't use something like rm -R .*
because the .*
input pattern is expanded by the shell before being given to the rm command. It would result in recursively deleting all files that match those from the starting directory.
The Windows equivalent command (del -R .*
) is much simpler for the user because
the del
program does the work of expanding the wildchards for each subdirectory.