Determining If a Soft Link Already Exists [Closed]

How can you determine if a soft link already exists? I do not know how to determine this. I am a novice to Unix/Linux

As a user

$ ls -l 

if the first character of the mode bits (first column) is l it's a link.

If you just want to test this from a script,

$ test -L maybealink && echo "it is a symlink"
1

I am assuming you want to find symlinks to a specific file but don't know in what directory they may be. In that case type

find . -lname "path/to/filename" -ls

for instance

find . -lname "develop/source/itried.cpp" -ls

to find and show (starting in your current directory) any symlinks of the file named itried.cpp that lies in the directory develop/source.

or

find . -lname "*.cpp" -ls

to find symlinks to any .cpp files under your current directory.

the . after find tells it to search from your current directory down.

3

If there is soft-link in your current directory

Use ll command to display the file long list

Output will be like this

lrwxrwxrwx   1 root root    24 Dec  2  2011 default-java -> java-1.6.0-openjdk-amd64/
drwxr-xr-x   6 root root  4096 Oct  8 11:29 java-1.5.0-gcj-4.6/
lrwxrwxrwx   1 root root    24 Dec  2  2011 java-1.6.0-openjdk -> java-1.6.0-openjdk-amd64/
lrwxrwxrwx   1 root root    20 Jul 17 21:41 java-1.6.0-openjdk-amd64 -> java-6-openjdk-amd64/
-rw-r--r--   1 root root  2387 Jul 17 21:41 .java-1.6.0-openjdk-amd64.jinfo

if there is l before rwrwrw its softlink

lrwxrwxrwx   1 root root    24 Dec  2  2011 default-java -> java-1.6.0-openjdk-amd64/

This is a Softlink , java-1.6.0-openjdk-amd64 had been softlinked to default-java

Softlinks will be displayed in sky blue color

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest