MacOS – Find all hidden files that were hidden using the command “chflags hidden filename”

command linemacosterminal

I remember to hide an important file, but I can't find it anymore and I don't remember the name. I don't remember how I hid it, i.e., if just by inserting a prefix of . or using chflags hidden filename.

I tried to recover all hidden files (hidden because of the prefix .) under my desktop using the following command

find . -name '.*' | grep "^.DS_Store" > hidden-files.txt

and the resulting hidden-files.txt text file is empty. (Anyway, I'm not 100% sure if the command above is correct.)

Again, now I would like to retrieve recursively (as I'm doing with the previous command) all hidden files that were hidden using the command chflags hidden filename using the terminal (or without, but I would need to have a list of them or a path to them). Is it possible? If yes, how can I do it?

Edit 1

I think the command above doesn't work because grep does not accept input. Anyway, to solve the problem I think I just need to add xargs as follows

find . -name '.*' | xargs grep "^.DS_Store" > hidden-files.txt

Best Answer

This should work for you

find . ! -name '.' \( -name '.*' -o -flags hidden \)

which means find in the current directory, all file system objects, except do not list the current working directory- (! -name '.'), whose name begins with a dot or file flag is set to hidden.