Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I've noticed that ls -l doesn't only change the formatting of the output, but also how directory symlinks are handled:

> ls /rmn  logs ...

> ls -l /rmn
lrwxrwxrwx 1 root root 18 Feb 11  2011 /rmn -> /root/maintenance/

I'd like to get a detailed listing of what's in /rmn, not information about the /rmn symlink.

One work-around I can think of is to create a shell function that does something like this:

cd /rmn
ls -l
cd -

But that seems too hacky, especially since it messes up the next use of cd -. Is there a better way?

(I'm on CentOS 2.6.9)

share|improve this question

3 Answers 3

up vote 6 down vote accepted

See if your ls has the options:

 -H, --dereference-command-line
     follow symbolic links listed on the command line 
     follow each command line symbolic link that points to a directory

If those don't help, you can make your macro work without messing up cd - by doing:

(cd /rmn ; ls -l)

which runs in a subshell.

share|improve this answer
It does have -H, and that did the trick. Thank you! – romkyns Nov 20 '12 at 15:04
I really wish that --dereference-command-line-symlink-to-dir had a short form. – WChargin Apr 13 at 23:44

I don't quite get why the thinking about this simple problem has to be so complex - but perhaps I just got the question the wrong way. Anyways: when I needed a similar functionality, I used:

ls -lL

That did the trick in my case. From the ls man page:

-L, --dereference
     when showing file information for a symbolic link, 
     show  information  for  the file the link references
     rather than for the link itself

For instance, I've made me a /media/stick shortcut to access the data on my USB stick. ls -l /media/stick will show the actual link, while ls -lL /media/stick will show the contents on the USB stick.

After some deeper research about the difference between the inner workings of -H and -L, I finally came across an excellent article about this matter on Shallow Thoughts blog (even featuring some neat shell script tricks for your pleasure!)

This points out the subtle differences between the two options (way better than the original manual does!) as follows:

  • -H -- only dereference those links explicitly mentioned on the command line
  • -L -- dereference links even if they are not mentioned on the command line

(When these two are used with simple everyday tasks, there ought to be no difference in the output in general.)

Besides: Should you prefer to remember the long form (--option), it's most probably less cumbersome to memorize --dereference than the excessively long monster of --dereference-command-line-symlink-to-dir.

share|improve this answer
ls -l /rmn/

would do it or

ls -l /rmn/.

However, the behavior should not be different with and without -l. Have you got an alias for ls?

share|improve this answer
ls flags are crazy. -l makes -H default to off, as does -F. See coreutils - Which files are listed. – Mikel Nov 20 '12 at 15:01
@Mikel it appears that you are completely right about that. And yes, that's nuts. (also, I don't have an alias for ls, tried escaping it but the results are the same) – romkyns Nov 20 '12 at 15:05
Indeed it's even specified by POSIX. I was the one with an ls='ls -F' alias actually. – Stéphane Chazelas Nov 20 '12 at 18:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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