How can I find a path by providing only part of the path?

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?

hax0r_n_code

Posted 2013-06-17T02:15:06.200

Reputation: 215

Answers

5

You need to use -path or -ipath with wildcards

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

MikeFHay

Posted 2013-06-17T02:15:06.200

Reputation: 2 334

2

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

Ignacio Vazquez-Abrams

Posted 2013-06-17T02:15:06.200

Reputation: 100 516

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" – hax0r_n_code – 2013-06-17T02:20:05.750

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

Gangadhar

Posted 2013-06-17T02:15:06.200

Reputation: 321

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.

user231844

Posted 2013-06-17T02:15:06.200

Reputation: 21