Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com Oct 10 '11 at 22:34

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

add comment

3 Answers

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

share|improve this answer
add comment

A quick search led me to this:

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

or

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
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.