Exclude all hidden files and directories in solaris

findhiddensolarisunix

Unix newbie could use your help.

I'm using Solaris 10 and need to find all files, excluding all hidden files and directories. The ultimate goal is to put this in a script that will delete files 60+ days old on a server.

I tried:

find . ! ( -name '.*' -prune )

but it finds no files at all.

Any suggestions are appreciated.

Best Answer

I believe the problem is that you are excluding everything named ".*", and you are starting your search at "." (which matches your exclusion), so you are excluding everything. Also, I believe you are misusing the -prune flag (it's an action, like -print, and so isn't necessarily useful as part of a negated expression). Try this:

find . \( -name '.*' \! -name '.' -prune \) -o -print

This explicitly includes '.' in the search, and then excludes everything else matching .*. If you know that your starting point doesn't include any dotfiles, you can simplify this a bit:

find * \( -name '.*' -prune \) -o -print