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.
You'll probably want to read this Stack Overflow question: Making ls aware of “hidden” file flag.
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".