Linked Questions
13 questions linked to/from How to resolve symbolic links in a shell script
48 votes
2 answers
38k views
How can I derefence symbolic links in bash? [duplicate]
How can I take any given path in bash and convert it to it's canonical form, dereferencing any symbolic links that may be contained within the path? For example: ~$ mkdir /tmp/symtest ~$ cd /tmp/...
1 vote
1 answer
2k views
In shell, check what /bin/sh is symlinked to [duplicate]
In Shell script, How can I check if /bin/sh is softlink'ed to dash or bash, I may have /bin/sh -> dash or /bin/sh -> bash
2 votes
2 answers
316 views
Bash - how to remove trailing "/bin/java" in commandline? [duplicate]
I cannot work this out, seems my command in awk is not good enough: Basically I'd like to extract information from a simple Linux ls -l: ls -l /etc/alternatives/java lrwxrwxrwx. 1 root root 29 Apr ...
0 votes
0 answers
100 views
Portable way to read symlink destination in shell [duplicate]
Is there a way to portably (at least Linux and macOS) get the destination of a symlink in a (Posix) shell script? In an old program, I found ls -lad "bin" 2> /dev/null | awk '{ printf (&...
1102 votes
36 answers
1.9m views
How to get full path of a file?
Is there an easy way I can print the full path of file.txt ? file.txt = /nfs/an/disks/jj/home/dir/file.txt The <command> dir> <command> file.txt should print /nfs/an/disks/jj/home/...
456 votes
26 answers
174k views
How can I get the behavior of GNU's readlink -f on a Mac? [closed]
On Linux, the readlink utility accepts an option -f that follows additional links. This doesn't seem to work on Mac and possibly BSD based systems. What would the equivalent be? Here's some debug ...
227 votes
6 answers
199k views
Mount host directory with a symbolic link inside in docker container
I mounted the container with this parameter: -v /home/test/:/home/test Inside /home/test in the host there is a symbolic link pointing to a /mnt/ folder. But that link, although can be seen where ...
48 votes
3 answers
78k views
Bash: how to get real path of a symlink? [duplicate]
Is it possible, executing a file symlinked in /usr/local/bin folder, to get the absolute path of original script? Well, .. I know where original file is, and I know it because I am linkging it. But, .....
11 votes
5 answers
21k views
How to get script file path inside script itself when called through sym link
When I need to get path to the script file inside script itself I use something like this: `dirname $0` that works file until I call the script through sym link to it. In that case above code prints ...
7 votes
4 answers
2k views
How to list all members of a symlink-chain?
Finding the java binaries can be painful: which java gives /usr/bin/java lh $(which java) gives /usr/bin/java -> /etc/alternatives/java lh /etc/alternatives/java gives /etc/alternatives/java -> /...
8 votes
3 answers
2k views
How can you use pure unset shell builtin? Can you write shell scripts that are immune to tampering?
I mean I want to use unset that is not a shell function itself. If I could do that, I could make sure that command is pure by running #!/bin/sh { \unset -f unalias command [; \unalias unset command [ ...
1 vote
2 answers
2k views
truncate a string in bash with variable expansion formatting
I am trying to truncate a string in bash, specifically to get into the directory of an executable linked by a symlink. For example: [alva@brnzn ~ $] ls -algh $(which python3.4) lrwxr-xr-x 1 admin ...
0 votes
1 answer
3k views
How to resolve a symbolic link to a parent directory in a shell script?
The following line introduces the local variable PROGUARD_HOME within a shell script: PROGUARD_HOME=`dirname "$0"`/.. This points to the parent folder of the shell script. The script executes ...