Linux

How to List Symbolic Links in a Linux Directory

In this article, we are going to explain the various methods of listing all the symbolic links in a given Linux directory.
Captain Salem 3 min read
How to List Symbolic Links in a Linux Directory

This tutorial is based on Debian 12 alpha1, codename Bookworm. However, this tutorial will work any version of GNU/Linux.

Symbolic links, also known as soft links are file types that points to the location of another directory or file within the filesystem. They are essential files available in any Linux systems. They can allow you to remove the need to type the full path to a given file or directory. They can also allow you to link various tools and services in simple commands.

Let us start at the root level and discuss how we can list all the soft link in the entire filesystem. For that, we can use the find command in the / directory.

To narrow down the search, we need to pass the type parameter as -l which denotes soft links.

The command is as provided below:

sudo find / -type l

Output:

/proc/898/ns/net
/proc/898/ns/uts
/proc/898/ns/ipc
/proc/898/ns/pid
/proc/898/ns/pid_for_children
/proc/898/ns/user
/proc/898/ns/mnt
/proc/898/ns/cgroup
/proc/898/cwd
/proc/898/root
/proc/898/exe
/boot/vmlinuz
/boot/vmlinuz.old
/boot/initrd.img
/boot/initrd.img.old

NOTE: There a lot of soft links in the linux filesystem. Use tools such as awk or grep to locate files matching a specific pattern.

Method 2 - List All Symbolic Files in the Current Working Directory.

Another method to narrow down your search is to list all the files in your current working directory. For that, you can change the search location for the find command to the current directory as:

sudo find . -type l

Example:

cd /etc
sudo find . type -l

The command lists all the soft links in the /etc directory as:

/modules-load.d/modules.conf
./xdg/systemd/user
./localtime
./rc4.d/S01anacron
./rc4.d/S01rsyslog
./rc4.d/S01console-setup.sh
./rc4.d/S01avahi-daemon
./rc4.d/S01plymouth
./rc4.d/K01speech-dispatcher
./rc4.d/S01lightdm
./rc4.d/S01hddtemp
./rc4.d/S01ssh
./rc4.d/S01cron
./rc4.d/S01network-manager
./rc4.d/S01saned
./rc4.d/S01spice-vdagent
./rc4.d/S01sudo
./rc4.d/S01dbus
./lighttpd/conf-enabled/90-javascript-alias.conf
./rc0.d/K01alsa-utils
./rc0.d/K01udev
./rc0.d/K01network-manager

You can also provide an absolute path to a target directory to show the symbolic links. The command syntax is as listed below:

sudo find /path/to/directory -type l 

Example:

sudo find /var -type l

Output:

/var/lib/ghostscript/CMap/UniJISPro-UCS2-V
/var/lib/ghostscript/CMap/GB-EUC-V
/var/lib/ghostscript/CMap/Adobe-CNS1-3
/var/lib/ghostscript/CMap/HKm314-B5-V
/var/lib/ghostscript/CMap/KSC-Johab-H
/var/lib/ghostscript/CMap/UniJIS2004-UTF8-H
/var/lib/ghostscript/CMap/KSCms-UHC-HW-H
/var/lib/ghostscript/CMap/UniKS-UTF8-H
/var/lib/ghostscript/CMap/B5-H
/var/lib/ghostscript/CMap/B5pc-V
/var/lib/ghostscript/CMap/NWP-V
/var/lib/ghostscript/CMap/UniHojo-UTF16-H
/var/lib/ghostscript/CMap/UniKS-UTF32-V
/var/lib/ghostscript/CMap/Adobe-GB1-2
/var/lib/ghostscript/CMap/Adobe-Japan1-UCS2
/var/lib/ghostscript/CMap/H
/var/lib/ghostscript/CMap/UniGB-UCS2-V
/var/lib/ghostscript/CMap/Adobe-Japan1-5
/var/lib/ghostscript/CMap/RKSJ-H
/var/lib/ghostscript/CMap/Identity-V
/var/lib/ghostscript/CMap/UniCNS-UCS2-H
/var/lib/ghostscript/CMap/Add-H

End.

Final

This tutorial guided you through simple method of listing symbolic links in the entire filesystem, the curent directory, or any target directory without your filesystem.

Leave us a comment down below and share!!

If you enjoy our content, please consider buying us a coffee to support our work:

Share
Comments
More from GeekBits

Join us at GeekBits

Join our members and get a currated list of awesome articles each month.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to GeekBits.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.