Show full path to file in terminal
57,583
Solution 1
I found it:
sudo apt-get install realpath
Then:
realpath MY_FILE
Solution 2
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
/home/xieerqi/out.txt
I personally use it in my own scripts whenever it's necessary to get full path of a file
Solution 3
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
.
Related videos on Youtube
Author by
Karl Morrison
Updated on September 18, 2022Comments
-
Karl Morrison over 1 year
I have a file. I'd like to echo out the full path to it in the terminal.
Which command would?
-
fugitive over 7 yearsYou can use
locate
command frommlocate
package as well. -
George Vasiliou over 7 yearsFor searchin in current directory you can also use
find $PWD -name
instead offind . -name
, and all the resutls will include the real path instead of the./
symbol. -
Rahul over 7 years@GeorgeVasiliou Thanks for feedback. I'll update my answer.
-
Stefan Falk over 5 yearsImho it's not necessary to install something for that kind of task ..
-
Karl Morrison over 5 years@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.
-
Karl Morrison over 5 years$ readlink -e README.md readlink: illegal option -- e usage: readlink [-n] [file ...]
-
Sergiy Kolodyazhnyy over 5 years@KarlMorrison Are you using Ubuntu ? Ubuntu uses GNU version of readlink which has that option. BSD and Mac os don't
-
Stefan Falk over 5 yearsRahu and Sergiy Kolodyazhnyy already provided two answers which do not require the installation of an additional program. :)
-
sleblanc almost 4 years
realpath
is part of coreutils, and as such should already be available on 99% of systems running Linux.