Shell - list only symbolic links

Hi,

Im trying to manipulate an output for a command but I dont see to be getting it right..

Basically what I want to do is list only the symbolic links and them format the output to a table:

The first ls is this one:

> ls -la
total 148
lrwxrwxrwx  1 root root      14 May 12 22:11 addfs -> ../addfs_3.2.0
drwxr-xr-x  8 dpa  dpgrpa  4096 Apr 14 21:05 backup
drwxr-xr-x  2 dpa  dpgrpa 12288 May 12 22:11 bin
lrwxrwxrwx  1 root root      33 May 12 22:11 boa -> /opt/smarttrust/dpa/bom_6.4.2/boa
lrwxrwxrwx  1 root root      33 May 12 22:11 bom -> /opt/smarttrust/dpa/bom_6.4.2/bom
lrwxrwxrwx  1 root root      24 May 12 22:11 campaignmanager -> ../campaignmanager_4.2.0
lrwxrwxrwx  1 root root      12 May 12 22:11 cca -> ../cca_6.2.0
drwxr-xr-x  2 dpa  dpgrpa  4096 Apr 14 21:05 clientcacerts
drwxr-xr-x  3 dpa  dpgrpa  4096 Apr 14 21:05 clientcerts
lrwxrwxrwx  1 root root      16 May 12 22:11 cluster -> ../cluster_2.1.0
drwxr-xr-x  2 dpa  dpgrpa 12288 May 12 22:11 config


Then I came up with this command:

>ls -la | grep "\->" |awk '{$1=$2=$3=$4=$5=$6=$7=$8=$9=$10=""; print $0}'  --  (there are for sure better options to achieve that)
          ../addfs_3.2.0
          /opt/smarttrust/dpa/bom_6.4.2/boa
          /opt/smarttrust/dpa/bom_6.4.2/bom
          ../campaignmanager_4.2.0
          ../cca_6.2.0
          ../cluster_2.1.0

And with this output I would like to have this:

Products                     Version
============================
addfs                           3.2.0              
bom                             6.4.2
campaignmanager    4.2.0
cca                                6.2.0
.


Some problems I had were the lines differ on their prefix... (../addfs_3.2.0 and /opt/smarttrust/dpa/bom_6.4.2/boa). So I couldnt figure a way to have it formatted into the table above...

Is it possible to do what Im trying to do..?

Tks,
Joao
joaotellesAsked:
Who is Participating?
 
simon3270Commented:
If you assume that none of the filenames or paths has a space in it (they really shouldn’t for system files like this!), and there is only one entry with an underscore in the target path, then

ls -la | awk '/->/{print $11}' | sed 's,.*/\([a-z][a-z]*\)_\([0-9][0-9.]*\).*,\1 \2,' | sort -u

Then you just have to add the headers.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.