Home > front end >  Why do `ls /bin` and `ls -l /bin` print different files
Why do `ls /bin` and `ls -l /bin` print different files

Time:09-06

I'm new to shell and still practicing on it. When I typed

ls /bin

The shell prints many files

'['                                   mousetweaks
 aa-enabled                           mscompress
 aa-exec                              msexpand
 aa-features-abi                      mt
 aconnect                             mt-gnu
..

But when I typed

ls -l /bin

I was expecting the same output file in long format, but it seems like the shell just gives me a soft link

lrwxrwxrwx 1 root root 7  Sept  5 15:22 /bin -> usr/bin

I can't figure out why.

CodePudding user response:

The POSIX specification for ls says this:

-l
(The letter ell.) Do not follow symbolic links named as operands unless the -H or -L options are specified. Write out in long format (see the STDOUT section). Disable the -C, -m, and -x options.

If you want to change the behavior, in addition to the two options specified above, you can also put a trailing slash after the name (i.e., /bin/ instead of /bin).

  • Related