How can I find the path for a given file?

How can I find the directory for a file?

In my Unix shell, I know how to use the ls command, but it shows just the name of the file. I need the path too. How do I get it?

3 Answers

echo "$PWD/filename" will print the name of the filename, including the path.

1

A quick search led me to this:

find / -name "filename" -type f -print

or

locate filename
1

In Linux you can use readlink -f; on BSDs realpath might work.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like