Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

how to either ignore or deal with Icon$'\r' files on macOS

I never thought I'd hate anything more than the .DS_Store files that
macOS makes, but it turns out there's something much worse:


These are some kind of file that is uses to give a special icon to a
folder when viewed in the Finder, but the files themselves aren't
visible in Finder (why they didn't make them '.icon' files, I have no

Most of the time I can just ignore them, but I've run into one folder
where I need to be able to do something like

for i in *

but I do NOT want to do whatever if "$i" is one of these stupid Icon$'\r' files.

The problem is that I can't figure out how to match it.

for i in *
    if [ "$i" != "Icon$'\r'" ]
        echo "$i"

doesn't work. It will echo "Icon" without the last character(s).

I don't even know what to try to match, because it shows up as that
weird "$'\r'" thing, but not if I do `ls`

% /bin/ls -l Icon$'\r'
-rw-rw-rw-@ 1 luomat  staff  0 Jun 20 18:42 Icon?

and if I run `ls` through `cat -v` I get this:

%  /bin/ls -l | fgrep -i icon | cat -v
-rw-rw-rw-@ 1 luomat  staff          0 Jun 20 18:42 Icon^M

I don't even know how to `rm` it reliably and safely, and macOS will
just re-generate it anyway, so it felt like it was time to figure out
how to properly ignore it.

Any suggestions welcome.


TJ Luoma
TJ @ MacStories
Personal Website: luo.ma (aka RhymesWithDiploma.com)
Twitter: @tjluoma

Messages sorted by: Reverse Date, Date, Thread, Author