Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Is there a way to show only the hidden and invisible files in a directory using the command line?

For instance ls -a | grep "^\." will show all the files hidden by a period as the first character, but what about files hidden with the invisible flag or listed in .hidden (mostly deprecated in practice, don't worry about that one so much.)?

share|improve this question

1 Answer 1

If the files are indexed by Spotlight and files in subdirectories can be included, you could use mdfind:

mdfind kMDItemFSInvisible=1 -onlyin .

Or test for both GetFileInfo -av (attribute invisible) and if the name starts with a period:

shopt -s dotglob nullglob; for f in *; do [[ $(GetFileInfo -av "$f") = 1 || $f = .* ]] && echo "$f"; done

GetFileInfo is part of the command line tools package that can be downloaded from Xcode's preferences or from developer.apple.com/downloads.

Different ways to list only files that start with a period:

shopt -s nullglob; printf %s\\n .[^.]* ..?*
shopt -s dotglob nullglob; GLOBIGNORE='. ..'; printf %s\\n *
ls -a | grep -E '^(\.[^.]|\.\.[^$])'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.