• We did not send an email asking for donations - please read this post.

Bash Script - readlink-all.sh - Follow Filesystem Links

SlowCoder

Gold Member
Gold Supporter
Joined
May 2, 2022
Messages
456
Reaction score
316
Credits
3,611
Sometimes I need to know where a filesystem link points. Sometimes I find that a link points to a link, which then points to a link, and so on, until the final destination file or directory is reached.

The command readlink is good for outputting the next link in a chain of links, or to the final destination file/directory, using the -f option. But why doesn't it show us the whole chain?

So I wrote this quick-n-dirty script to output all links in the chain:
Bash:
if ! [[ -e $1 ]]; then exit; fi

CUR_LINK=$1
DEST="$(readlink -f $1)"
while [[ $CUR_LINK != $DEST ]]; do
    echo "$CUR_LINK"
    CUR_LINK="$(readlink $CUR_LINK)"
done
echo "$DEST"

I suspect most people won't want or need this. But I'm posting my random scripts in the prospect that people may learn or be encouraged to write their own scripts.
 


KGIII

Super Moderator
Staff member
Gold Supporter
Joined
Jul 23, 2020
Messages
7,310
Reaction score
6,312
Credits
59,239
Hmm...

I wonder if it's worth making a stickied thread - "Linux.org User-created Helpful Shell Scripts"?

People searching would still find the posts just fine. People browsing could browse the thread.
 
OP
SlowCoder

SlowCoder

Gold Member
Gold Supporter
Joined
May 2, 2022
Messages
456
Reaction score
316
Credits
3,611
Hmm...

I wonder if it's worth making a stickied thread - "Linux.org User-created Helpful Shell Scripts"?

People searching would still find the posts just fine. People browsing could browse the thread.
Creating a single general thread and stickying it would be very cool. I could just do my normal posts, and link them in that thread.
 

KGIII

Super Moderator
Staff member
Gold Supporter
Joined
Jul 23, 2020
Messages
7,310
Reaction score
6,312
Credits
59,239
Also, feel free to move your existing scripts to the new thread. Giving it some content to get it started may make more folks notice and want/remember to contribute.
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Linux.org Hosting Donations
Consider making a donation

Members online


Top