2

Given the ll command outputs as follows

#> ll
lrwxrwxrwx ...

How to determine if a soft link's target is a directory or a file from "lrwxrwxrwx"?

3

You can use the -F parameter to ls to get:

   -F, --classify
          append indicator (one of */=>@|) to entries

i.e.:

# ln -s videos Videos
# ls -l
lrwxrwxrwx. 1 guido guido    6 Jan 23 14:11 videos -> Videos
# ls -lF
lrwxrwxrwx. 1 guido guido    6 Jan 23 14:11 videos -> Videos/

Anyway, I'd suggest you create symlinks to directories like this:

# ln -s Videos/ videos

in this case, you get the trailing slash even without the classify option.

1

The output of ll, which I assume is a shell alias for ls -l, does not contain this information in the mode/permissions of the symlink. On Linux (symlink(2)):

   The  permissions  of  a  symbolic link are irrelevant; the ownership is
   ignored when following the link, but is checked when removal or  renam-
   ing  of  the  link is requested and the link is in a directory with the
   sticky bit (S_ISVTX) set.

In addition to ls suggested elsewhere, there are some methods which are less verbose, and lend themselves to scripting.

file supports -L which causes it to follow (dereference) symlinks:

$ file /usr/local/bin/xzcat
/usr/local/bin/xzcat: symbolic link to `xz'

$ file -L /usr/local/bin/xzcat
/usr/local/bin/xzcat: ELF 32-bit LSB executable, [...]

$ file  /var/adm
/var/adm: symbolic link to `log'

$ file -L /var/adm   
/var/adm: directory

The -L option is not POSIX but should work on any contemporary Linux and *BSD. It will follow multiple symlinks (which ls does not). For more robust use it also supports various output formats, e.g. file -L -b --mime-type /var/adm, and -0 for zero-delimited filenames.

GNU statis even easier:

$ stat -c %F /var/adm
symbolic link

$ stat -L -c %F /var/adm
directory

The -L option works the same as for file, the -c %F option instructs stat to output only the type of the file, see the stat(1) man page for more. *BSD stat is not quite the same as GNU stat, the format strings are different, use -f %HT instead.

0

I think what you want is:

ls -l filename

man is your friend:

man ls
  • That doesn't work. The output cannot tell me if the filename is linked a directory or a file. It just tell me the file-entry is a soft link. – xmllmx Jan 23 '15 at 3:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.