readlink question

For discussions about programming and projects not necessarily associated with Porteus.

readlink question

Postby Rava » 17 Mar 2016, 16: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
User avatar
Rava
Contributor
Contributor
 
Posts: 1280
Joined: 11 Jan 2011, 03:46
Location: Germany
Distribution: Porteus 3.1.0 x86-64 XFCe

Re: readlink question

Postby port » 23 Mar 2016, 17: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
port
Black ninja
Black ninja
 
Posts: 99
Joined: 18 Feb 2016, 10:25
Location: Spain
Distribution: Linux porteus 3.2.2 KDE


Return to Programming



Who is online

Users browsing this forum: No registered users and 1 guest