How to get full path of a file?

I suppose you are using Linux.

I found a utility called realpath in coreutils 8.15.

realpath -s file.txt
/data/ail_data/transformed_binaries/coreutils/test_folder_realpath/file.txt

Since the question is about how to get the full/absolute path of a file and not about how to get the target of symlinks, use -s or --no-symlinks which means don't expand symlinks.

As per @styrofoam-fly and @arch-standton comments, realpath alone doesn't check for file existence, to solve this add the e argument: realpath -e file


Use readlink:

readlink -f file.txt