Questions tagged [readlink]

Use this tag for questions related to the readlink command which prints resolved symbolic links or canonical file names.

25 questions
112
votes
3 answers

What's the difference between "realpath" and "readlink -f"

I've read a lot about the realpath command and how it has been deprecated with readlink -f being now recommended.  I have also seen in some places that the reason why realpath was introduced was for the lack of such functionality in readlink and…
Felipe Leão
  • 1,285
  • 2
  • 9
  • 10
8
votes
2 answers

explain the options of readlink command

Can someone please explain me following options of readlink command in simple language: -f, --canonicalize canonicalize by following every symlink in every component of the given name recursively; all but the last component …
Alex Jones
  • 6,223
  • 17
  • 51
  • 83
7
votes
1 answer

Looking for tested utility to get the absolute path to a relative symlink target

NB: In the original title of this post, I used the word standard in the everyday sense of "well-established" (and therefore time-tested, as a contrast to quick solutions I could roll myself). In the context of Unix-talk, however, the word standard…
kjo
  • 14,779
  • 25
  • 69
  • 109
5
votes
2 answers

readlink -f and -e option description not clear

-f, --canonicalize canonicalize by following every symlink in every component of the given name recursively; all but the last component must exist -e, --canonicalize-existing canonicalize by following every symlink in every component of the given…
jlas
  • 95
  • 1
  • 5
4
votes
2 answers

How do I test for link to a link?

I want to test whether a file is a link to another link. I tried readlink but it doesn't work the way I need it: [email protected],1:~/subdir1 $ ll lrwxrwxrwx 1 pi pi 13 Apr 10 14:34 hellolink -> subdir2/hello lrwxrwxrwx 1 pi pi 9 Apr 10 14:34…
Arjen
  • 188
  • 8
3
votes
1 answer

Overwrite symlink with original file

I have a directory with some symlink file, for example: /home/user/symlink/$(*symlink_file_name1*).mkv /home/user/symlink/$(*symlink_file_name2*).mkv And I have another directory with the original file (of the symlink…
3
votes
3 answers

Real current directory

Obviously I know about pwd and readlink, but is there a command to find out the real absolute path to the current directory (ie, resolving links and dots)?
Jonathan H
  • 2,303
  • 3
  • 20
  • 27
2
votes
2 answers

How do I resolve a relative path in a POSIX shell if readlink/realpath is not available?

If neither utility readlink, nor realpath is available (I think today mostly from GNU coreutils?), what can I use in POSIX shell scripting to resolve a relative path? There is a realpath C function, though. So maybe one of the other utilities uses…
finefoot
  • 2,940
  • 2
  • 21
  • 41
2
votes
1 answer

How do I restore files removed from /usr/bin?

TL;DR at the bottom. Background: The following occured on my CentOS 6.10 production server. I was using a browser based terminal program to run the program Midnight Commander which is a console-based file explorer. Unfortunately, the mouse support…
iskyfire
  • 133
  • 4
2
votes
2 answers

How to tell without knowing the mount point that a device UUID is mounted?

System: Linux Mint 19.1 Cinnamon 64-bit, based on Ubuntu 18.04 LTS. I would like to know if it is possible to get the following information: Is this UUID (of a block device) mounted or not? (without knowing the mount point) In spite, I have played…
Vlastimil Burián
  • 27,586
  • 56
  • 179
  • 309
2
votes
2 answers

Trace route of a symbolic link

I want to resolve a symbolic link with the additional option to print the whole linkage. For example I want to run a command like readlink -f "symlink2" which reports each entry of the linkage. In other words if you would resolve the symbolic link…
Hölderlin
  • 1,160
  • 5
  • 14
  • 34
1
vote
0 answers

Can realpath command completely replaced by readlink command?

Given that realpath command does not exists on every unix platform, I would like to replace realpath with readlink command in order to make my shell script as cross-platform as possible. The thing is that realpath has the --relative-to parameter…
1
vote
1 answer

combine ls -alt with readlink

I have a directory containing a lot of symbolic links and some huge subdirectories. I want to get a detailed listing, sorted by time, of just the files in the parent directory, but with targets replacing links if the files are symbolic links. The…
Leo Simon
  • 443
  • 1
  • 5
  • 11
1
vote
1 answer

copying a symlink to a target file using cp -t

I have a symlink to a file on my Ubuntu system, and I need to copy the original file to a different directory and have a new name there. I am able to copy it to a different directory using readlink -ne my_symlink | xargs -0 cp -t /tmp/ But I am…
1
vote
3 answers

Option to readlink on Linux and MacOS that will return filepath if it's not a symlink

I have this: file_path="/actual/file/path" read_link="$(readlink "$file_path")" # just in case it's a symlink readlink will echo an empty string if it's not a symlink? Is there an option to readlink that will just echo the original path if it's…
Alexander Mills
  • 9,330
  • 19
  • 95
  • 180
1
2