Apple - How do I search all hidden files that are in hidden folders using Terminal?

mdfind seems to ignore a lot of hidden files. mdfind 'kMDItemFSInvisible==1&&kMDItemFSName==filename' does list .DS_Store files, but not for example .bash_history. I haven't found any way to search for files in some hidden directories like /private/etc/.

Anyway, Find Any File is a lot faster than find.

Find Any File is a program for Mac OS X that lets you search for files on your disks.

  • Contrary to Spotlight, it does not use a database but instead uses the file system driver's fast search operations, where available. This lets you search for file properties such as name, dates, size, etc., but not for file content (use Spotlight or EasyFind for that).
  • Find Any File can find files that Spotlight doesn't, e.g. those inside bundles and packages and in inside folders that are usually excluded from Spotlight search.
  • Finally, it is quite fast. A search only takes a few seconds on an internal hard disk or SSD. Try for yourself!

Assuming that by “hidden file” you mean files whose name begins with a dot or that are located somewhere under a directory whose name begins with a dot, and not other forms of invisible files, the following command prints the names of all hidden files. It's slow as it goes over all the file names everywhere on your system.

sudo find / -name '.*' \( -type d -exec find {} \; -prune -o -print \)

Explanation:

  • -type d -exec find {} \; -prune executes find on every directory (whose name matched .*), and skips descending into that directory because of the -prune.
  • -type d … -o -print causes all non-directories that match .* to be printed.

If you're looking for a file with a specific name or pattern:

sudo find / -name 'Foo*' -path '*/.*'

The */.* pattern on the whole path forces matches to be under a hidden directory.

You may want to add -xdev after the / to avoid traversing special filesystems and removable disks.


Try the locate command. You will have to sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist first and wait for the locate DB to be generated.