Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Bash, how do I safely determine what a soft link points to?

Tags:

bash

symlink

I need to process a number of directories, determine what files in them are symlinks, and what they link to. This sounds simple, but I have no control over the presence of control or other characters in the file names, and I need a robust solution.

So, given a file of arbitrary name, how do I safely determine what it links to, when the link destination can also have arbitrary contents?

like image 299
swestrup Avatar asked Jul 18 '10 16:07

swestrup


People also ask

How do I identify a soft link?

Showing soft link using Find command in UnixWhen you use the find command with option type and specify the type as small L ( l for the link), it displays all soft links in the specified path.

How do you find the target of a symbolic link?

The Symlink option (Symlink Target Operations) only appears in the context menu from ClearCase Explorer after right-clicking on an actual symbolic link. If the symlink target is in another VOB, then that VOB must also be mounted on the local system.

How do you check whether a link is a hard one or a soft link?

If you find two files with identical properties but are unsure if they are hard-linked, use the ls -i command to view the inode number. Files that are hard-linked together share the same inode number. The shared inode number is 2730074, meaning these files are identical data.

How do I find linked files in Linux?

Use the ls -l command to check whether a given file is a symbolic link, and to find the file or directory that symbolic link point to. The first character “l”, indicates that the file is a symlink. The “->” symbol shows the file the symlink points to.


1 Answers

readlink -f <linkname> 

See the readlink(1) man page for Linux, FreeBSD, NetBSD, OpenBSD, DragonFly or the GNU coreutils info page.

like image 135
eduffy Avatar answered Sep 19 '22 02:09

eduffy