Posted: . At: 9:51 AM. This was 4 years ago. Post ID: 14030
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.



Sponsored



How to list all symbolic links in a directory easily with the shell.


List all symbolic links in a folder is very easy, this is how to find just the symlinks and not bother with any other files.

This example shows how to use the find command to do this.

4.4 Tue Feb 04 jason@Yog-Sothoth 0: $ find . -type l
./boom
./chocolate-strife-setup
./LS
./heretic
./doom
./cowthink
./chocolate-doom-setup
./strife
./chocolate-hexen-setup
./hexen
./chocolate-heretic-setup

Install the symlinks utility, then run it like this to show symlinks in the current directory.

sudo apt install symlinks

Then it may be run, and it will do the job very well.

4.4 Tue Feb 04 jason@Yog-Sothoth 0: $ symlinks -v .
absolute: /usr/games/boom -> /etc/alternatives/boom
relative: /usr/games/chocolate-strife-setup -> chocolate-setup
relative: /usr/games/LS -> sl
absolute: /usr/games/heretic -> /etc/alternatives/heretic
absolute: /usr/games/doom -> /etc/alternatives/doom
relative: /usr/games/cowthink -> cowsay
relative: /usr/games/chocolate-doom-setup -> chocolate-setup
absolute: /usr/games/strife -> /etc/alternatives/strife
relative: /usr/games/chocolate-hexen-setup -> chocolate-setup
absolute: /usr/games/hexen -> /etc/alternatives/hexen
relative: /usr/games/chocolate-heretic-setup -> chocolate-setup

How to list only the filenames of the symlinks in a directory with awk.

4.4 Tue Feb 04 jason@Yog-Sothoth 0: $ ls -hula | awk /lrw/'{print $9}'
boom
chocolate-doom-setup
chocolate-heretic-setup
chocolate-hexen-setup
chocolate-strife-setup
cowthink
doom
heretic
hexen
LS
strife

That could be very useful for a script, this would be a great starting point.

4.4 Tue Feb 04 jason@Yog-Sothoth 0: $ ls -hula | awk /lrw/'{print $9, $6, $7, $8, $10, $11}'
boom Feb 4 09:26 -> /etc/alternatives/boom
chocolate-doom-setup Feb 4 09:26 -> chocolate-setup
chocolate-heretic-setup Feb 4 09:26 -> chocolate-setup
chocolate-hexen-setup Feb 4 09:26 -> chocolate-setup
chocolate-strife-setup Feb 4 09:26 -> chocolate-setup
cowthink Feb 4 09:26 -> cowsay
doom Feb 4 09:26 -> /etc/alternatives/doom
heretic Feb 4 09:26 -> /etc/alternatives/heretic
hexen Feb 4 09:26 -> /etc/alternatives/hexen
LS Feb 4 09:26 -> sl
strife Feb 4 09:26 -> /etc/alternatives/strife

The version above, shows the filename, the date, and the filename it links to. Play around with the columns to get different outputs.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.