Bash Command to Get Absolute Path for a File

If you are inside a directory location in Terminal and you want to get the absolute path of a particular file then you can make use of the readlink command with -f or --canonicalize flag.

readlink - print resolved symbolic links or canonical file names

man page:


bash-3.2$ readlink -f cert.pem 

How to Get Absolute Path of a file using bash

As you can see, the output is the absolute file path with the file name.

If you are on macOS then you can also make use of the realpath command.

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail:

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap