Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

migrated from Oct 10 '11 at 22:34

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

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

share|improve this answer

A quick search led me to this:

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


locate filename
share|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

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

share|improve this answer

You must log in to answer this question.