Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 277255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T01:02:59+00:00 2026-05-12T01:02:59+00:00

On Linux, the readlink utility accepts an option -f that follows additional links. This

  • 0

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 information:

$ which readlink; readlink -f
/usr/bin/readlink
readlink: illegal option -f
usage: readlink [-n] [file ...]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T01:02:59+00:00Added an answer on May 12, 2026 at 1:02 am

    readlink -f does two things:

    1. It iterates along a sequence of symlinks until it finds an actual file.
    2. It returns that file’s canonicalized name—i.e., its absolute pathname.

    If you want to, you can just build a shell script that uses vanilla readlink behavior to achieve the same thing. Here’s an example. Obviously you could insert this in your own script where you’d like to call readlink -f

    #!/bin/sh
    
    TARGET_FILE=$1
    
    cd `dirname $TARGET_FILE`
    TARGET_FILE=`basename $TARGET_FILE`
    
    # Iterate down a (possible) chain of symlinks
    while [ -L "$TARGET_FILE" ]
    do
        TARGET_FILE=`readlink $TARGET_FILE`
        cd `dirname $TARGET_FILE`
        TARGET_FILE=`basename $TARGET_FILE`
    done
    
    # Compute the canonicalized name by finding the physical path 
    # for the directory we're in and appending the target file.
    PHYS_DIR=`pwd -P`
    RESULT=$PHYS_DIR/$TARGET_FILE
    echo $RESULT
    

    Note that this doesn’t include any error handling. Of particular importance, it doesn’t detect symlink cycles. A simple way to do this would be to count the number of times you go around the loop and fail if you hit an improbably large number, such as 1,000.

    EDITED to use pwd -P instead of $PWD.

    Note that this script expects to be called like ./script_name filename, no -f, change $1 to $2 if you want to be able to use with -f filename like GNU readlink.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code works well in Mac/Linux, but not in Windows. import mmap import os
On Linux sed -i will modify the input files in place. It doesn't work
Linux provides the stime(2) call to set the system time. However, while this will
In Linux, what is the difference between /dev/ttyS0 and /dev/ttys0 ? I know that
I can't understand the operation of the readlink systemcall in Linux. Can anyone explain
I'm calling command line programs connected by pipes. All this works on Linux for
I'm writing a simple dual timer in Python. (I'm running Linux, and this should
I'm in the process of porting some code from Linux to Mac OS X.
Linux binaries are usually dynamically linked to the core system library (libc). This keeps
On Linux, it seems that appcfg.py saves credentials when I use it to upload

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.