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?

link|improve this question
feedback

migrated from stackoverflow.com Oct 10 '11 at 22:34

This question came from our site for professional and enthusiast programmers.

3 Answers

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

link|improve this answer
feedback

A quick search led me to this:

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

or

locate filename
link|improve this answer
That assumes you know the name of the file, but not where it is. Since the OP says ls can show the file, I don't think that's the problem. – Keith Thompson Oct 11 '11 at 0:52
feedback

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

link|improve this answer
feedback

Your Answer

 
or
required, but never shown