Take the 2-minute tour ×
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
biweekly.sh  daily.sh  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
add comment

3 Answers

up vote 4 down vote accepted

See if your ls has the options:

 -H, --dereference-command-line
     follow symbolic links listed on the command line 
 --dereference-command-line-symlink-to-dir
     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
add comment
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
1  
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. –  Stephane Chazelas Nov 20 '12 at 18:10
add comment

I don't quite get that, but maybe I got the question the wrong way. 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.

share|improve this answer
add comment

Your Answer

 
discard

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.