I have been searching for a while, but can't seem to get a succinct solution. I have a Mac with a folder that I want to clean of all hidden files/directories - anything hidden. It used to be a Eclipse workspace with a lot of .metadata/.svn stuff, and I'm fine with all of it being removed. How can I do this (either with a shell script, Applescript, etc). Thanks a lot in advance!
rm -rf /some/path/* deletes all non-hidden files in that dir (and subdirs). rm -rf /some/path/. * deletes all hidden files in that dir (but not subdirs) and also gives the following error/warning: rm: cannot remove directory: `/some/dir/.
To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r . Directories that are removed with the rmdir command cannot be recovered, nor can directories and their contents removed with the rm -r command.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With