12

I need to find some configs buried in some hidden folders and can't recall where they are to navigate to them directly Cmd+Shift+G.

I did a sudo find -name Foo* (slow), but none of the returned files were in hidden folders.

What is the easiest way to search all hidden files?

1
  • Note: Using sudo is unnecessary unless you need to search in directories that you do not have access to. Searching in hidden directories does not require elevated privileges, if that's why it's being used in your example.
    – Chris Page
    Commented Jul 4, 2012 at 23:06

6 Answers 6

18

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!
7

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.

1
  • Ah, thanks. And it looks like -x is preferred now, as -xdev is deprecated. Commented Feb 21, 2012 at 17:33
5

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.

2
  • 5
    It's such a nuisance that Spotlight doesn't pick up hidden / (dot-)files, because mdfind is vastly superior to slocate. Commented Feb 20, 2012 at 17:35
  • In recent macOS versions, this is no longer a real solution -- the locate.updatedb command is run using the nobody user, which does not have permission to view files in user home directories, which most people probably want Commented Jul 2, 2022 at 20:21
2

EasyFind is an excellent alternative app to get the job done. It's free and easy. You can search for text in files (even invisible ones). <= This may be an easier way to find your config files.

You can get it from the App Store https://itunes.apple.com/us/app/easyfind/id411673888?mt=12

Disclaimer: I am not affiliated with the developer.

1
  • Does not work on APFS-formatted drives. Commented Sep 22, 2018 at 16:12
2

ag can search hidden files by file name.

For instance:

ag --hidden -g ".swiftlint.yml" ~/

How to install

brew install the_silver_searcher

https://github.com/ggreer/the_silver_searcher

rg is faster than ag.

rg --files --hidden ~/ |rg  ".swiftlint.yml"

How to install

brew install ripgrep

https://github.com/BurntSushi/ripgrep

2
  • How does this help in the situation described by the OP (who apparently doesn't know the name of the hidden files)?
    – nohillside
    Commented May 19, 2020 at 7:47
  • 1
    It works as well. For instance, rg --files --hidden ~/ |rg ".swiftlint*"
    – webcpu
    Commented May 19, 2020 at 7:57
-1

If you want to search .DS_Store hidden files, this command works well.

du -a | grep .DS_Store

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .