I have a file. I'd like to echo out the full path to it in the terminal.

Which command would?


4 Answers 4


Use readlink with -e flag. Not only it gives you full path to file, it also presents real path of the symlinks

$ readlink -e ./out.txt                                                                                                  

I personally use it in my own scripts whenever it's necessary to get full path of a file

  • 1
    $ readlink -e README.md readlink: illegal option -- e usage: readlink [-n] [file ...] Nov 27, 2018 at 12:09
  • @KarlMorrison Are you using Ubuntu ? Ubuntu uses GNU version of readlink which has that option. BSD and Mac os don't Nov 27, 2018 at 12:13

I found it:

sudo apt-get install realpath


realpath MY_FILE
  • 4
    You can use locate command from mlocate package as well.
    – fugitive
    Jan 13, 2017 at 13:15
  • Imho it's not necessary to install something for that kind of task .. Nov 27, 2018 at 9:17
  • @StefanFalk Care to answer with a very easy solution then?) I don't like this either but it's quick and shows me what I need. Nov 27, 2018 at 12:08
  • Rahu and Sergiy Kolodyazhnyy already provided two answers which do not require the installation of an additional program. :) Nov 27, 2018 at 13:39
  • realpath is part of coreutils, and as such should already be available on 99% of systems running Linux.
    – sleblanc
    Jun 18, 2020 at 4:19

If you don't know the location of the file use find command.

find / -name MY_FILE

It will print full path of MY_FILE starting from /.

or you can use find $PWD -name MY_FILE to search in current directory.

If you know the location of MY_FILE then go to folder containg MY_FILE and use

pwd command to print the full path of MY_FILE.

  • 2
    For searchin in current directory you can also use find $PWD -name instead of find . -name, and all the resutls will include the real path instead of the ./ symbol. Jan 13, 2017 at 13:32
  • @GeorgeVasiliou Thanks for feedback. I'll update my answer.
    – Rahul
    Jan 13, 2017 at 13:35

Here is a function to show paths to files, you may just need the "fpath=...." part ?

pathtofile () { : "gives full path to files given in parameters.";
  for f in "$@"; do
      cd -P "$(dirname "$f")" && \
      printf '%s\n' "$(pwd)/$(basename "${f}")" || \
      { echo "__An error occured while determining path to file: '${f}'."\
             "Maybe your user can't access its directory, most likely?__"
      }  )"
    printf "Full path to: %s\n          is: %s\n" "'${f}'" "'${fpath}'";

Use with:

pathtofile   file1  ../file2  /some/pathwithsymlink/file3

The important part: cd -P somedir : shows the full "real" path to somedir.

Not the answer you're looking for? Browse other questions tagged or ask your own question.