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
fpath="$(
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}'";
done
}
Use
readlink
with-e
flag. Not only it gives you full path to file, it also presents real path of the symlinksI personally use it in my own scripts whenever it's necessary to get full path of a file
I found it:
Then:
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 containgMY_FILE
and usepwd
command to print the full path ofMY_FILE
.Here is a function to show paths to files, you may just need the "fpath=...." part ?
Use with:
The important part: cd -P somedir : shows the full "real" path to somedir.