How to find symbolic link by a target name

Find symbolic link by a target name. It sounds simple and it definitely is.

Find symbolic links inside /usr directory whose case-sensitive content is exactly ssh.

$ find /usr/ -type l -lname "ssh" -exec stat --format="%N" {} \;
'/usr/share/bash-completion/completions/autossh' -> 'ssh'
'/usr/share/bash-completion/completions/slogin' -> 'ssh'
'/usr/share/bash-completion/completions/sftp' -> 'ssh'
'/usr/share/bash-completion/completions/scp' -> 'ssh'
'/usr/bin/slogin' -> 'ssh'

Find symbolic links inside /usr/bin directory whose case-insensitive content contains alternatives keyword and case-insensitive symbolic link name contains awk keyword.

$ find /usr/bin -type l -ilname "*alternatives*" -iname "*awk*" -exec stat --format="%N" {} \;
'/usr/bin/nawk' -> '/etc/alternatives/nawk'
'/usr/bin/awk' -> '/etc/alternatives/awk'

Find symbolic links inside /etc/alternatives directory whose case-sensitive content contains vim keyword.

$ find /etc/alternatives/ -type l -lname "*vim*" -exec stat --format="%N" {} \;
'/etc/alternatives/vi' -> '/usr/bin/vim.basic'
'/etc/alternatives/ex.ru.1.gz' -> '/usr/share/man/ru/man1/vim.1.gz'
'/etc/alternatives/ex.fr.1.gz' -> '/usr/share/man/fr/man1/vim.1.gz'
'/etc/alternatives/ex.pl.1.gz' -> '/usr/share/man/pl/man1/vim.1.gz'
'/etc/alternatives/view.ja.1.gz' -> '/usr/share/man/ja/man1/vim.1.gz'
'/etc/alternatives/vi.pl.1.gz' -> '/usr/share/man/pl/man1/vim.1.gz'
'/etc/alternatives/vi.ja.1.gz' -> '/usr/share/man/ja/man1/vim.1.gz'
'/etc/alternatives/ex.it.1.gz' -> '/usr/share/man/it/man1/vim.1.gz'
'/etc/alternatives/vimdiff' -> '/usr/bin/vim.basic'
'/etc/alternatives/ex.1.gz' -> '/usr/share/man/man1/vim.1.gz'
'/etc/alternatives/vi.1.gz' -> '/usr/share/man/man1/vim.1.gz'
'/etc/alternatives/vi.ru.1.gz' -> '/usr/share/man/ru/man1/vim.1.gz'
'/etc/alternatives/vi.it.1.gz' -> '/usr/share/man/it/man1/vim.1.gz'
'/etc/alternatives/view.it.1.gz' -> '/usr/share/man/it/man1/vim.1.gz'
'/etc/alternatives/vim' -> '/usr/bin/vim.basic'
'/etc/alternatives/rvim' -> '/usr/bin/vim.basic'
'/etc/alternatives/vi.fr.1.gz' -> '/usr/share/man/fr/man1/vim.1.gz'
'/etc/alternatives/view' -> '/usr/bin/vim.basic'
'/etc/alternatives/view.fr.1.gz' -> '/usr/share/man/fr/man1/vim.1.gz'
'/etc/alternatives/rview' -> '/usr/bin/vim.basic'
'/etc/alternatives/view.ru.1.gz' -> '/usr/share/man/ru/man1/vim.1.gz'
'/etc/alternatives/view.pl.1.gz' -> '/usr/share/man/pl/man1/vim.1.gz'
'/etc/alternatives/ex.ja.1.gz' -> '/usr/share/man/ja/man1/vim.1.gz'
'/etc/alternatives/ex' -> '/usr/bin/vim.basic'
'/etc/alternatives/view.1.gz' -> '/usr/share/man/man1/vim.1.gz'

Find symbolic links inside /etc/alternatives directory whose case-sensitive content contains vim keyword but not a case-sensitive /usr/share/man/ path.

[email protected]:~/name$ find /etc/alternatives/ -type l -lname "*vim*" -and -not -lname "/usr/share/man/*" -exec stat --format="%N" {} \;
'/etc/alternatives/vi' -> '/usr/bin/vim.basic'
'/etc/alternatives/vimdiff' -> '/usr/bin/vim.basic'
'/etc/alternatives/vim' -> '/usr/bin/vim.basic'
'/etc/alternatives/rvim' -> '/usr/bin/vim.basic'
'/etc/alternatives/view' -> '/usr/bin/vim.basic'
'/etc/alternatives/rview' -> '/usr/bin/vim.basic'
'/etc/alternatives/ex' -> '/usr/bin/vim.basic'

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system.