Q. How can I convert a relative path to absolute path for using them in shell script.
Some times it required to get absolute path from a given relative path. For example I am in /home/surendra and relative path to /etc/apache2 will be ../../etc/apache2 for this relative path I require absolute path so that the value is constant with the script irrespective of my directory changes. This can be acheived by using command readlink.
readlink -f relativepath
Example1: I am at /home/surendra I want to know what will be the absolute path to ../../etc/ from that directory.
email@example.com:~$ readlink -f ../../etc
Example2: I am at /etc/samba and I have ../apache/mods-enabled which is relative to /etc/samba, I want to know the absolute path.
firstname.lastname@example.org:~$ cd /etc/samba/
email@example.com:/etc/samba$ readlink -f ../apache2/mods-enabled/
Latest posts by Surendra Anne (see all)
- FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018
- wget download a file to a directory in Linux/Unix - June 4, 2018
- GIT: How to compare two GIT branches? - June 3, 2018