I'm trying to combine arguments to the
ls command to list a directory content. What I'm basically trying to achieve is listing the directory dereferencing all links, but showing explicitly that the item listed is a link. I've tried combining the
--classify options, but instead of showing the link symbol (
@) I get a
* since the link targets an executable file.
Any thoughts on how I can get such result? I'm open to alternatives other than
I actually use other options from the
ls command. My current command along with their options is the one bellow:
ls -ogq -LB --group-directories-first --time-style=long-iso
I intend to parse the output inside an application I'm building and can't use the default link output with the arrow (
->). Other items on the directory (e.g. folders and files) must also be listed.
Just to clarify, I'm developing a Java apllication that uses a SSH2 API to connect to servers and list directories. The result from the listing is then used to populate a tree using the jsTree jQuery plugin . Currently The command I cited above give's me the following output:
felipe@simba:/mnt/drive$ ls -ogq --group-directories-first --time-style=long-iso total 12 drwxr-sr-x 2 4096 2014-06-11 18:04 folder1 drwxr-sr-x 6 4096 2014-06-27 19:35 folder2 dr-Sr-s-wt 2 4096 2014-06-27 13:51 folderWithPermissions -rw-r--r-- 1 0 2014-06-30 10:42 file.txt lrwxrwxrwx 1 49 2014-06-30 11:36 linkTeste -> folder2/dir/otherfile.txt
By applying a regular expression I can identify what is a folder, file or link by looking at the permissions. But when I have a link I need to list only the link name, instead of
name -> destination. If I use the
-L option for the
ls command only the link name is outputed and I get the referenced destination's permissions (what is a good thing), since the
-L option dereferences the link, but this way I can't know that the link is actually a link.
felipe@simba:/mnt/drive$ ls -ogq -L --group-directories-first --time-style=long-iso total 12 drwxr-sr-x 2 4096 2014-06-11 18:04 folder1 drwxr-sr-x 6 4096 2014-06-27 19:35 folder2 dr-Sr-s-wt 2 4096 2014-06-27 13:51 folderWithPermissions -rw-r--r-- 1 0 2014-06-30 10:42 file.txt -rwxr-xr-x 1 0 2014-06-27 18:40 linkTeste
I need to list only the link name, know it is a link and know what the destination is (file, folder or link). I can handle different kinds of output since I'm going to apply a regular expression anyway.
stat are also welcome.