1

I was doing my routine work today and it seems the stat and file commands in the terminal don‘t show if a file is a symbolic link:

flow2k@myPad:dir ln -s aa.iml superlink
flow2k@myPad:dir stat superlink
16777220 11057327 lrwxr-xr-x 1 flow2k staff 0 6 "Dec  2 13:25:34 2017" "Dec  2 13:25:34 2017" "Dec  2 13:25:34 2017" "Dec  2 13:25:34 2017" 4096 8 0 superlink

How can I see whether something is a symlink?

  • What kind of output would you expect to show it is a symlink? – nohillside Dec 3 '17 at 16:52
  • @patrix Being somewhat accustomed to Linux, I expected the string "symbolic link" to be explicitly shown in the output, like the samples shown here unix.stackexchange.com/a/49326/227169 – flow2k Dec 3 '17 at 23:25
  • Well, macOS ain‘t Linux :-) – nohillside Dec 4 '17 at 5:12
2

The l in lrwxr-xr-x shows that is is a (symbolic) link.
Use readlink file to show where the symbolic link points to.

The stat manual page states:

When invoked as readlink, only the target of the symbolic link is printed. If the given argument is not a symbolic link, readlink will print nothing and exit with an error.

2

BSD stat and file differ from their Linux counterparts but the BSD versions can mimic the Linux output. From the manual for file:

-h, --no-dereference
         option causes symlinks not to be followed (on systems that support symbolic links).

file -h /etc
/etc: symbolic link to private/etc

and from the manual for stat

 -x      Display information in a more verbose way as known from some Linux distributions.

stat -x /etc
File: "/etc"
Size: 11           FileType: Symbolic Link
Mode: (0755/lrwxr-xr-x)         Uid: (    0/    root)  Gid: (    0/   wheel)
Device: 1,4   Inode: 419701    Links: 1
Access: Sun Apr 16 14:39:45 2017
Modify: Sun Apr 16 14:39:45 2017
Change: Sun Apr 16 14:41:19 2017    

You must log in to answer this question.

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