6

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?

4 Answers 4

5

You need to use -path or -ipath with wildcards

find . -type d -ipath "*/find/this/path"
2

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

1
  • 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"
    – nullByteMe
    Jun 17, 2013 at 2:20
2

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
2

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .