> ## Content Index
> Fetch the complete content index at: https://linuxhandbook.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Follow Symbolic Links
- URL: https://linuxhandbook.com/follow-symbolic-link/
- Published: 2022-09-29T10:35:10.000Z
- Updated: 2024-05-14T15:44:59.000Z
- Description: You got a symbolic link and wondering about the actual source file? Here's how to follow symlinks in Linux.
- Author: Sagar Sharma
- Tags: Tips

A [symbolic link](https://linuxhandbook.com/symbolic-link-linux/) (also known as soft link) is a kind of shortcut to another file. It's heavily used in Linux for shared libraries.

But how do you know to which original file the link points to?

You can use the ls command for this purpose. Surprised? Don't be. The long listing `ls -l` displays where a symbolic link points:

```
ls -l /path/to/file
```

For example, I've created a soft link named `MyTorrents` that targets another disk so my command will be:

```
ls -l /home/sagar/Symbolics/MyTorrents
```

![](https://linuxhandbook.com/content/images/2022/09/Find-symbolic-link-using-ls-command.png)

A symbolic link is indicating to its original file

However, this is not a foolproof way to follow the symbolic link to the original file because if it's a multilayer link (a link pointing to another link that points to a file), the ls command won't display the source file.

## How to Find Target File of Symbolic Link in Linux

It's a no-brainer that with enough skills, you do have multiple ways of accomplishing the same thing, especially if we consider Linux.

So I'll be utilizing the following command line utilities to follow symbolic links:

- readlink
- realpath
- stat
- file

You can [use the ln command to create links](https://linuxhandbook.com/ln-command/) and practice while you follow this tutorial.

### 1\. Using readlink command

A specific utility that is just made to accomplish our goal. Yes, that's readlink. 

It is quite easy to use and available by default on every Linux distro. So just give a path of symbolic link with `readlink` command and that's it.

```
readlink /path/to/symbolic/link
```

My symbolic link is placed at `/home/sagar/Symbolics/MyTorrents` so my command would be:

```
readlink /home/sagar/Symbolics/MyTorrents
```

![use readlink to find source of symbolic link](https://linuxhandbook.com/content/images/2022/09/read-link-path-to-syslink.png)

But what **if your symbolic link involves multiple layers** such as one link indicted to another? Well, in that case, you'd have to use `-f` option. 

For this example, I've created a new symbolic link located at `/home/sagar/Documents/NewLink` and maps to the other link to have a better idea of how to deal with such scenarios: 

```
readlink -f /home/sagar/Documents/NewLink
```

![use readlink to get source of symbolic links when dealing with multiple latyers](https://linuxhandbook.com/content/images/2022/09/readlink-with--f-option.png)

### 2\. Using realpath command

As its name suggests, the [realpath utility is used to get the path of files and directories](https://linuxhandbook.com/get-file-path/) but the interesting thing is when used without any option, it can get us to the source of the symbolic link.

Using realpath even without any options is equivalent to using `readlink -f` so don't worry about being mapped to another symbolic link.

The syntax of realpath to follow symbolic link to the source file is:

```
realpath /path/to/symbolic/link
```

And after specifying the path, end result should look like this:

![use realpath command to find source of symbolic link](https://linuxhandbook.com/content/images/2022/09/using-realpath.png)

[Learn Linux Quickly - Linux Commands for BeginnersLearn Linux Quickly doesn’t assume any prior Linux knowledge, which makes it a perfect fit for beginners. Nevertheless, intermediate and advanced Linux users will still find this book very useful as it goes through a wide range of topics. Learn Linux Quickly will teach you the following topics:Insta…![](https://public-files.gumroad.com/variants/mkb3qijws0s0gb0g9l2wxggvscph/4ec519eb32080d4ff1ef08cba157dc2ac7dab092fa26aeca54e8e2b8f31f9a63)Gumroad![](https://public-files.gumroad.com/variants/wd03xyf089rdb915v2jlyed3uymg/3953c12f08a92d2317e5f6a4fe2f6dd48702c3beec8a2173335cffa31a3561ec)](https://linuxhandbook.gumroad.com/l/mEsrwA?ref=linuxhandbook.com)

### 3\. Using stat command

[The stat utility](https://linuxhandbook.com/stat-command/) is used to get the status of files and can also be utilized to find the original source of the symbolic link.

Just give a path of the symbolic link to the `stat` command and that's it.

```
stat /path/to/symbolic/link
```

![use stat command to find source of symbolic link](https://linuxhandbook.com/content/images/2022/09/using-stat-command-to-find-source.png)

And if you find the other details unnecessary, you can use the `-c%N` option to filter them out. Not the easiest option to remember and hence use the man or help command to recall it.

```
stat -c%N /path/to/symbolic/link
```

![stat command with less clutter showing original source of symbolic link](https://linuxhandbook.com/content/images/2022/09/stat-with--c-N.png)

### 4\. Using file command

Well, [using the file command](https://linuxhandbook.com/file-command/) is quite easy and you're required to follow the same syntax that you saw earlier with other examples. 

A file command with a path to a symbolic link. That's all you'd need!

```
file /path/to/symbolic/link
```

![use file command to find source of symbolic link](https://linuxhandbook.com/content/images/2022/09/file-command-for-symbolic-link.png)

## Final Words

If you're dealing with multilayer soft link layers, I recommend using the first two ways of following symbolic links.

These utilities are quite basic and do not require any complex syntax but if you're still confused, let me know in the comments.