12

I created a symbolic link (specifically a symbolic link & not a Finder alias which bash can't follow) to a directory in my home folder using ln -s link $HOME/directory & now I wish to hide the link in the Finder so I don't have to look at it. Normally I would use chflags hidden link to accomplish this, but of course that would affect the directory, not the link. I can't use the standard leading dot because the name of the link itself is important for applications that look for it & a leading dot changes the name.

So my question is, how do I hide the symbolic link without hiding the directory it links to or changing its name?

EDIT: I intentionally kept my question vague because it's a small experiment with the Finder, but here's some more details to clarify exactly what I'm trying to do.

Finder uses the $HOME/Desktop folder for the desktop itself, it doesn't matter if it's a link, alias or a completely different folder called “Desktop” (such as the home folder itself) as long as it's in the $HOME directory.

I made a symbolic link to my home directory named “Desktop” in order to populate the contents of Finder's desktop with the contents of my home folder (if you try this, it doesn't take effect until you login again, also this was done on 10.6). That also places the symbolic link itself on my desktop of course which I don't want to see in either a Finder window or on the desktop itself. If I were to rename it to “.Desktop” in order to hide it, it would hide, but the link between my home folder & my desktop would also be broken.

1
  • look like you are stuck between a rock and a hard-place :-)
    – nik
    Aug 30, 2009 at 7:31

4 Answers 4

18
SetFile -P -a V filename

The '-P' flag will make it operate on the symlink and not what it points to. The '-a V' portion will turn on the invisible attribute to hide it in the Finder.

1
  • Excellent, this worked perfectly for me. Thank you.
    – A. L.
    Aug 30, 2009 at 8:08
8

You can also use chflags -h to not follow symlinks:

chflags -h hidden /path/to/symlink
3
  • Might be worth mentioning that -H is a common flag for “dereference symlinks given on the command-line, but not those encountered in tree traversal” (the behavior in between -L (follow all symlinks) and -P (follow no symlinks)). That might be the source of some confusion. Jan 16, 2014 at 2:21
  • 2
    This worked great. For those that stumbled here after accidentally hiding the underlying file/folder (not the symlink), it can be restored using: chflags nohidden /path/to/regularfile. The symlink won't be affected.
    – tresf
    Jun 16, 2020 at 19:02
  • Excellent. Is there a way to also hide the symlink from the ls command, unless using ls -a, like files that start with ., but without having to use a prepended period in the name? Sep 4, 2020 at 4:16
-2

Rename link to .link

0
-2

As drvdijk said, you can rename the symlink to .link. Items whose names start with dots are normally hidden from GUI file browsers (like the Finder) and most command-line programs. For example, ls won't show it unless you pass -a (show --all files) or -A (show --almost-all files).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .