We already knew what is Symlinks or Symbolic links or Soft links and how to find and delete broken Symlinks from our Linux system. Today, we are going to learn how to list Symlinks on Linux. If you have created some symlinks a long time ago and completely forget about them, this quick tip will help you to easily find the symbolic links using "find" command.
List Symlinks on Linux
To list all of the symlinks or symbolic links or soft links in a Linux system, run:
$ sudo find / -type l
Here,
- / - represents the entire filesystem.
- -type - refers the file type.
- l - refers the symlink.
This command will search for all available symbolic links in the entire filesystem. It will take a while depending upon the size of your filesystem. Please be patient!
If you want to limit the symlink search within a specific directory, mention its path as shown below.
For example, the following command will list all of the soft links in the current directory:
$ find . -type l
Please note the single dot (.) in the above command. In Linux, the single dot (.) is used to represent the current(present) directory. The double dot (..) is used to represent the parent directory.
Sample output:
./snap/multipass/current ./snap/multipass/1597/.config/autostart ./snap/multipass/1597/config/autostart/multipass.gui.autostart.desktop ./snap/multipass/1784/.config/autostart ./snap/multipass/1784/config/autostart/multipass.gui.autostart.desktop ./.local/share/webkitgtk/databases/indexeddb/v0 find: ‘./.dbus’: Permission denied ./.config/spyder-py3/spyder.lock ./Downloads/Tor browser/Browser/.config/ibus/bus ./.mozilla/firefox/htoypxlg.default-1563118799416/lock
If you want to search symlinks in a different directory, replace the dot (.) with the directory path.
If you want detailed output including timestamps, file permissions, owner and group, use the following command instead:
$ find . -type l -ls
Sample output:
4458987 0 lrwxrwxrwx 1 sk sk 4 Mar 6 13:58 ./snap/multipass/current -> 1784 11927799 0 lrwxrwxrwx 1 sk sk 19 Mar 5 11:20 ./snap/multipass/1597/.config/autostart -> ../config/autostart 11932200 4 lrwxrwxrwx 1 sk sk 72 Feb 27 15:30 ./snap/multipass/1597/config/autostart/multipass.gui.autostart.desktop -> /snap/multipass/1597/usr/share/multipass/multipass.gui.autostart.desktop 11534358 0 lrwxrwxrwx 1 sk sk 19 Mar 17 11:51 ./snap/multipass/1784/.config/autostart -> ../config/autostart 11666096 4 lrwxrwxrwx 1 sk sk 72 Mar 6 13:58 ./snap/multipass/1784/config/autostart/multipass.gui.autostart.desktop -> /snap/multipass/1784/usr/share/multipass/multipass.gui.autostart.desktop 5246237 0 lrwxrwxrwx 1 sk sk 51 Feb 12 20:14 ./.local/share/webkitgtk/databases/indexeddb/v0 -> /home/sk/.local/share/webkitgtk/databases/indexeddb find: ‘./.dbus’: Permission denied 4459630 0 lrwxrwxrwx 1 sk sk 5 Jan 24 17:39 ./.config/spyder-py3/spyder.lock -> 18461 4340805 0 lrwxrwxrwx 1 sk sk 25 Feb 15 15:21 ./Downloads/Tor\ browser/Browser/.config/ibus/bus -> /home/sk/.config/ibus/bus 4328111 0 lrwxrwxrwx 1 sk sk 20 Mar 17 11:56 ./.mozilla/firefox/htoypxlg.default-1563118799416/lock -> 192.168.225.37:+2642
As you may have noticed in the above outputs, the find command searches for the symlinks in the current directory and its sub-directories.
If you want to list all symlinks down one level in the current directory, use maxdepth flag like below.
$ find . -maxdepth 1 -type l
Another way to find the list of symlinks in the current directory:
$ find . -type l -printf '%p -> %l\n'
This will recursively list all the symlinks in the current directory. And also, it shows the actual files it points to.
Sample output:
./snap/multipass/current -> 1784 ./snap/multipass/1597/.config/autostart -> ../config/autostart ./snap/multipass/1597/config/autostart/multipass.gui.autostart.desktop -> /snap/multipass/1597/usr/share/multipass/multipass.gui.autostart.desktop ./snap/multipass/1784/.config/autostart -> ../config/autostart ./snap/multipass/1784/config/autostart/multipass.gui.autostart.desktop -> /snap/multipass/1784/usr/share/multipass/multipass.gui.autostart.desktop ./.local/share/webkitgtk/databases/indexeddb/v0 -> /home/sk/.local/share/webkitgtk/databases/indexeddb find: ‘./.dbus’: Permission denied ./.config/spyder-py3/spyder.lock -> 18461 ./Downloads/Tor browser/Browser/.config/ibus/bus -> /home/sk/.config/ibus/bus ./.mozilla/firefox/htoypxlg.default-1563118799416/lock -> 192.168.225.37:+2642
For more details, refer man pages.
$ man find
Hope this helps.
1 comment
Hi,
Very good article
thanks a lot