ls-command acting strange, HELP?

Discussion in 'Mac Programming' started by dickguertin, Jan 20, 2017.

  1. dickguertin macrumors newbie

    dickguertin

    Joined:
    Sep 4, 2010
    Location:
    Mountain View, CA
    #1
    I'm using Terminal.app in Yosemite, and I've followed a path through several directories. I'm now at

    $HOME/Library/d1/d2/d3/d4 (the d's are directory names). ls -l shows me the content of d4, and one of the entries is a symlink that looks like this: ColorSync -> ../../../../ColorSync

    If I just do "ls -l ColorSync", I see the long form of display ending with what you see above. Notice there are four (4) backup steps, which would say ColorSync exists in Library. If I try "ls -ldL ColorSync", I get the same response as for just the -l option alone. That's because there is no ColorSync file in Library. But if I removed the 'd' and use "ls -lL ColorSync", I'm told "ColorSync: No such file or directory". If the symlink points to a directory, such as "d1 -> ../../../d1", then "ls -ldL d1" shows the d1 directory. If I leave out the 'd', is shows the contents of the directory. How do I get "ls -ldL something" to show me a directory at symlink location, OR tell me a file is missing at that location?
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    If the final target of the symlink is expected to be a directory, you can force it to be resolved by appending "/." to the symlink's pathname. Since "." always refers to "the referenced directory itself", then it's always safe to use it in any pathname expression involving directories. This only works when the expected final target is a directory. You can't use it to force the resolution of ordinary files.

    For example, "/etc" might be a symlink. To force it to resolve to the target directory, use "/etc/." instead.

    The "." can also be repeated. For example, "/bin", "/bin/.", and "/bin/./." all refer to the same thing.

    I'll also refer you to the commands 'stat' and 'readlink'.
     
  3. mfram macrumors 65816

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #3
    Just because there is a symbolic link doesn't mean the target of the symbolic link actually exists. It may not. You can make a symbolic link to whatever path you want. Your command said the ColorSync directory doesn't exist. So clearly that symbolic link points to a directory that doesn't exist.
     

Share This Page