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.

Let's say I need to find this path /<some_where_in_root>/find/this/path and the only information I have is /find/this/path. What would be the best means of locating the full directory?

I basically have a program that creates a directory and after the directory is created I'd like to see if a path now exist within the directory that was created.

So far I've tried find . -type d -name "/find/this/path" but this obviously interprets /find/this/path as a string. Is there any way to use find in this situation? Would it be best to just parse the path I have and take the path portion and do a search on this string?

share|improve this question

migrated from stackoverflow.com Jun 17 '13 at 10:25

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

4 Answers 4

up vote 4 down vote accepted

You need to use -path or -ipath with wildcards

find . -type d -ipath "*/find/this/path"
share|improve this answer

The -path predicate (and it's case-insensitive variant, -ipath) will allow you to search the entire tree for that exact text.

share|improve this answer
    
That's what I thought, but it is now obvious to me that I've been doing it incorrectly. I've tried find . -ipath "/find/this/path" –  inquisitor Jun 17 '13 at 2:20

execute these two commands, method1:

root@developer~:# updatedb

root@developer~:# locate /find/this/path

method2:

root@developer~:# tree |grep /find/this/path

the results will consists full path of /find/this/path

also try this run these from /

root@developer~:# cd /

root@developer~:/#updatedb
root@developer~:/#locate /find/this/path
root@developer~:/#tree |grep /find/this/path
share|improve this answer

works in all flavors of nix:

applemcg.$ find / -type d -name this | grep find/this/path

and a little advice, when asking for help. preface your first reference to a path of this sort with the word "directory", as in "directory path". it took a minute to realize you were not referring to the (csh) path or PATH variable.

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.