LS Command – How to Use Long Format (-l) While Following Directory Symlinks

lssymlink

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)

Best Answer

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.

Related Question