This is my setup in /tmp/test/

if I use ls -l

-rw-r--r--  1 rubo77 rubo77    0 Okt 21 04:15 a
-rw-r--r--  1 rubo77 rubo77    2 Okt 21 04:16 b
drwxr-xr-x  2 rubo77 rubo77 4,0K Okt 21 03:58 c
lrwxrwxrwx  1 rubo77 rubo77    1 Okt 21 03:57 d -> c
lrwxrwxrwx  1 rubo77 rubo77    1 Okt 21 03:58 e -> a
lrwxrwxrwx  1 rubo77 rubo77    2 Okt 21 03:59 f -> nofile

If I use just ls I see only the files without details:

a b c d e f

ls -F appends an indicator (one of */=>@|) to entries

a  b  c/  d@  e@  f@

How can I achieve this display?

a  b  c/  d->c/  e->a  f->nofile
  • lame answer that doesn't quite do what you want it to: ls -l | grep "->". there's probably a way to get rid of the additional information, but I don't really feel like poking through the manpage right now.
    – strugee
    Oct 21 '13 at 2:41
  • I "poked" through the manpage and there seems to be no such option for ls. But maybe with another command?
    – rubo77
    Oct 21 '13 at 2:44
  • I don't think this can be done in a compact way. Especially since since sometimes a link can point to a really long path to another file, and this would look odd: a b c/ d->~/dev/kernel/net/wireless/mac80211/blah.c e->../../../dir/file f->e. Furthermore, what if the link is pointing to another link; how is that handled? It may be worth scripting to you, but probably not a default put into ls or any other listing programs. Oct 21 '13 at 4:13
  • Not with ls. You'll have to do your own stat and readlink then your own formatting in columns (you could call ls to leverage the coloring). Oct 21 '13 at 15:47

    ls -l | while read response
            words=`echo $response | wc -w`      #count how many words are

            case "$words" in
                9) echo $response | cut -d " " -f9 # when file is not a symlink then the ouput prints only 9 fields
               11) echo $response | cut -d " " -f9-11 # when file is symlink its prints 11 fields indicating the target and symbol "->"

If you buffer the output you can send it to column :

echo "">$TMP
ls -l | while read response
        words=`echo $response | wc -w`

        case "$words" in
            9) echo $response | cut -d " " -f9 >>$TMP
           11) echo $response | cut -d " " -f9-11 >>$TMP
cat $TMP | column
rm $TMP

a simple solution with some more information:

ls -hago | column

also interesting (but without the links shown):
This will show all files with human-readable sizes in columns:

ls -sh

These commands will do the job:

ls -lah | awk '{print $5, $9$10$11}' | column -t | column


ls -hago --color=no| sed 's/^[^ ][^ ]* *[^ ][^ ]* \( *[^ ][^ ]*\) ............/\1/' | column

with coloring it works too, but doesen't look so ordered:

if [ -t 1 ]; then color=yes; else color=no; fi
ls -hago --color="$color"| sed 's/^[^ ][^ ]* *[^ ][^ ]* \( *[^ ][^ ]*\) ............/\1/' | column

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.