9

The ls /bin command shows many files. I need to get a detailed list. But the ls -l /bin command shows only 1 file.

Tell me, please, what is wrong?

1
  • $ ls -l $(echo $PATH | tr ':' '\n') will show you "all" your executables, and also where they or the /bin dirs are linked to, if that is the case.
    – Hannu
    Apr 11, 2022 at 21:41

1 Answer 1

21

Nothing is wrong.

/bin is a symlink that points to /usr/bin.

When you use the ls /bin command, the symlink is followed, and you're shown the contents of /usr/bin (where the symlink points).

However, with the ls -l /bin command, the symlink is not followed, and only the symlink itself is shown.

The reason may be found under the --dereference-command-line-symlink-to-dir option in the ls texinfo documentation (info ls or info coreutils 'ls invocation'):

‘--dereference-command-line-symlink-to-dir’
     Do not dereference symbolic links, with one exception: if a command
     line argument specifies a symbolic link that refers to a directory,
     show information for that directory rather than for the link
     itself.  This is the default behavior when no other
     dereferencing-related option has been specified (‘--classify’
     (‘-F’), ‘--directory’ (‘-d’), (‘-l’), ‘--dereference’ (‘-L’), or
     ‘--dereference-command-line’ (‘-H’)).

In this context, -l is an "other dereferencing-related option" and turns the behavior off.

If you use ls -lH /bin, you tell the command to specifically follow symlinks, and now you (properly) see the contents of /usr/bin.

/bin being a symlink to /usr/bin follows the UsrMerge package, which was introduced in Debian 10 in 2019, and thus adopted by the following versions of Ubuntu.

1
  • 2
    Another way to force dereferencing is to use ls -l /bin/
    – Stobor
    Apr 13, 2022 at 2:52

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.