How do you recursively delete all hidden files in a directory on UNIX?
find /path -iname ".*" -type f -delete ;
Ruby(1.9+)
ruby -rfileutils -e 'Dir["**/.*"].each{|x| FileUtils.rm(x) if File.file?(x)}'
rm -rf `find . -type f -regex '.*/\.+.+'`
If you want to delete directories, change -type f
for -type d
.
If you want to delete files and directories remove -type f
.
UPDATE thanks to commenters: This fails for files or directories with spaces. Use a better answer
You need to be very careful and test any commands you use since you probably don't want to delete the current directory (.
), the parent directory (..
) or all files.
This should include only files and directories that begin with a dot and exclude .
and ..
.
find . -mindepth 1 -name '.*' -delete
find . -name ".*" -print
I don't know the MAC OS, but that is how you find them all in most *nix environments.
find . -name ".*" -exec rm -rf {} \;
to get rid of them... do the first find and make sure that list is what you want before you delete them all.
The first "."
means from your current directory. Also note the second ".*"
can be changed to ".svn*"
or any other more specific name; the syntax above just finds all hidden files, but you can be more selective. I use this all the time to remove all of the .svn directories in old code.