How to obtain the absolute path of a file via Shell (BASH/ZSH/SH)? How to obtain the absolute path of a file via Shell (BASH/ZSH/SH)? bash bash

How to obtain the absolute path of a file via Shell (BASH/ZSH/SH)?


Use realpath

$ realpath example.txt/home/username/example.txt


Try readlink which will resolve symbolic links:

readlink -e /foo/bar/baz


#! /bin/shecho "$(cd "$(dirname "$1")"; pwd -P)/$(basename "$1")"