Skip to content

Instantly share code, notes, and snippets.

@xpe
Last active December 23, 2020 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xpe/5e13efef10c66d802500a84813915469 to your computer and use it in GitHub Desktop.
Save xpe/5e13efef10c66d802500a84813915469 to your computer and use it in GitHub Desktop.
Hiding macOS Icon Files

Hiding macOS Icon Files

If you customize a Finder icon, macOS will put an Icon file in that directory.

While ls -al will show the filename as Icon?, the real file name is Icon$'\r', which can be found using Zsh's autocomplete functionality. Yes, the last character is a carriage return. Why, you may ask. That's a fair question.

Anyhow, to apply the hidden flag to all icon files located recursively within the current directory, run this command:

find . -name Icon$'\r' -exec chflags hidden {} +

The hidden flag as used here will hide files in the Finder. It will not hide files from a simple ls command.

If you want to see which files in a directory have the hidden flag, use ls -lO. Note that the last character is an uppercase letter O, not a zero. The -O flag tells ls to include the file flags.

What's Next?

You'll probably want to read this Stack Overflow question: Making ls aware of “hidden” file flag.

Credits

This command is an improved version of 2fatgoat's answer on Reddit:

find . -name "Icon?" -exec chflags hidden {} +

But that command matches too many files, including "Icons".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment