LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   find file with dir/file pattern (https://www.linuxquestions.org/questions/linux-newbie-8/find-file-with-dir-file-pattern-893895/)

DBabo 07-26-2011 01:32 PM

find file with dir/file pattern
 
hello,
i'm just curious if i can search for the dir/file pattern in the single "find" command?
here is an example:

dir1/dir2/dir3/file.txt
dirXX/dirYY/dir2/dir3/file.txt
dir1/dir4/dir3/file.txt

i want to search for the pattern "dir2/dir3/file.txt"

Tinkster 07-26-2011 01:42 PM

man find
/regex


Cheers,
Tink

Noway2 07-26-2011 01:48 PM

Have you looked at the 'find' command. It has a lot of options, such as setting type to regular file, specifying the desired path, and even things like newer / older than a particular time. A simple example, assuming I am interpreting your examples correctly, would be like:
Code:

find ./dir1/dir2 -type f -name file.txt -print
Edit: I see that Tinkster beat me to it.

kmassare 07-26-2011 01:53 PM

The search directory or directories are given separately from the filename, so if you want to find a particular file, file.txt, in directory /home/me/myfiles you would search by:

find /home/me/myfiles -name file.txt

You can also search more than one directory for filenames or patterns, for example:

find /etc /var -name '*.log'

The find utility is a very powerful search tool. Refer to the man pages for more information.

DBabo 07-26-2011 02:17 PM

i think i didn't formulate my question right. Let me clarify :
i want to search for the pattern "dir2/dir3/file.txt", not from the current directory, but across several other directories.
The idea is that the same file (file.txt) maybe in several directories and to uniquely identify the right one i need to bring the 2 directories (above it) into equation...
hope this helps . If not - please let me know.

So in Noway2's example, i can't use dir1/dir2 as a starting search directory - because i should be able to search in any directory.

smth like this :
find directory_Blah -name 'dir2/dir3/file.txt'

I probably should also note that i'm stuck on Solaris. ( don't have gnu here )

To Tink:
man find
/regex
Pattern not found

:).
I did RTFM and nothing caught my eye. I tried playing with ' and \ as well as adding * instead of /. But that didn't help. apparently i'm missing smth obvious.

grail 07-26-2011 02:56 PM

Quote:

To Tink:
man find
/regex
Pattern not found
If that is the case then you have left out some information, ie like what system are you on and what version of find?

DBabo 07-26-2011 03:10 PM

Quote:

Originally Posted by grail (Post 4425894)
If that is the case then you have left out some information, ie like what system are you on and what version of find?

Sunos5.10 and hmmm. no idea what version of find it is ...

grail 07-26-2011 03:25 PM

This should tell you:
Code:

$ find --version

DBabo 07-26-2011 03:34 PM

Quote:

Originally Posted by grail (Post 4425926)
This should tell you:
Code:

$ find --version

find: illegal option -- version
find: [-H | -L] path-list predicate-list

crts 07-26-2011 04:55 PM

Quote:

Originally Posted by DBabo (Post 4425859)

smth like this :
find directory_Blah -name 'dir2/dir3/file.txt'

Hi,

I do not know if your 'find' has those options but you might want to search for '-path' and/or '-wholename' option in the manpage.

Tinkster 07-26-2011 05:17 PM

Quote:

Originally Posted by DBabo (Post 4425859)
i think i didn't formulate my question right. Let me clarify :
i want to search for the pattern "dir2/dir3/file.txt", not from the current directory, but across several other directories.
The idea is that the same file (file.txt) maybe in several directories and to uniquely identify the right one i need to bring the 2 directories (above it) into equation...
hope this helps . If not - please let me know.

So in Noway2's example, i can't use dir1/dir2 as a starting search directory - because i should be able to search in any directory.

smth like this :
find directory_Blah -name 'dir2/dir3/file.txt'

I probably should also note that i'm stuck on Solaris. ( don't have gnu here )

To Tink:
man find
/regex
Pattern not found

:).
I did RTFM and nothing caught my eye. I tried playing with ' and \ as well as adding * instead of /. But that didn't help. apparently i'm missing smth obvious.



Yeah, the find that comes with Solaris by default is an antique,
doesn't know half the features of GNU find.


Easiest will be to find . -type f | grep dir1/dir2/file.


Cheers,
Tink

DBabo 07-26-2011 10:39 PM

Quote:

Originally Posted by Tinkster (Post 4426027)
Yeah, the find that comes with Solaris by default is an antique,
doesn't know half the features of GNU find.


Easiest will be to find . -type f | grep dir1/dir2/file.


Cheers,
Tink

yeah, i gave up to make it work as i wanted and did exactly the same way you suggested. Thank you anyway!

Here is the link to find's man page, that looks like the one i;m dealing with http://www.bga.org/~lessem/psyc5112/...is/find.1.html

DBabo 07-26-2011 10:40 PM

Quote:

Originally Posted by crts (Post 4426004)
Hi,

I do not know if your 'find' has those options but you might want to search for '-path' and/or '-wholename' option in the manpage.

ehh, i looked for those - nope, nothing. See my previous comment. Maybe you can spot smth i failed to?


All times are GMT -5. The time now is 03:49 AM.