readlink question

For discussions about programming and projects not necessarily associated with Porteus.
Post Reply
User avatar
Rava
Contributor
Contributor
Posts: 1319
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 3.1.0 x86-64 XFCe
Location: Germany

readlink question

Post#1 by Rava » 17 Mar 2016, 15:56

Hi, readlink --help or man readlink say
-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 name recursively,
all components must exist
Me thinks the ones who coded readlink had a good reason why all but the last components of --canonicalize must exist. What would be a reason to have the last one non-existing or possible non-existing? I am quite sure the programmers had a good reason to make it so.
Cheers!
Yours Rava

port
Samurai
Samurai
Posts: 135
Joined: 18 Feb 2016, 09:25
Distribution: Linux porteus 3.2.2 KDE
Location: Spain

Re: readlink question

Post#2 by port » 23 Mar 2016, 16:49

for example to be able to create a new file:

Code: Select all

touch `readlink -f mydir/mylink/newfile`
newfile does not exist when executing readlink but the path to it is a valid canonical path, so you can safely create the file with touch

if you use simply readlink or readlink -e you will get an error

of course, I'm supposing mydir and mylink currently exists, i.e.

Code: Select all

% mkdir -p mydir/tmp/myfolder
% ln -s tmp/myfolder mydir/mylink
% touch `readlink -f mydir/mylink/newfile`
% ls mydir/mylink
newfile

Post Reply