LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-26-2011, 02:32 PM   #1
DBabo
Member
 
Registered: Feb 2003
Distribution: Scientific Linux 6, Fedora
Posts: 445

Rep: Reputation: 37
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"
 
Old 07-26-2011, 02:42 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
man find
/regex


Cheers,
Tink
 
Old 07-26-2011, 02:48 PM   #3
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Ubuntu 10.10, Slackware 64-current
Posts: 2,124

Rep: Reputation: 778Reputation: 778Reputation: 778Reputation: 778Reputation: 778Reputation: 778Reputation: 778
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.
 
1 members found this post helpful.
Old 07-26-2011, 02:53 PM   #4
kmassare
LQ Newbie
 
Registered: Apr 2011
Location: California, US
Distribution: Fedora
Posts: 28

Rep: Reputation: 8
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.
 
Old 07-26-2011, 03:17 PM   #5
DBabo
Member
 
Registered: Feb 2003
Distribution: Scientific Linux 6, Fedora
Posts: 445

Original Poster
Rep: Reputation: 37
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.

Last edited by DBabo; 07-26-2011 at 03:25 PM.
 
Old 07-26-2011, 03:56 PM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,250

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
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?
 
1 members found this post helpful.
Old 07-26-2011, 04:10 PM   #7
DBabo
Member
 
Registered: Feb 2003
Distribution: Scientific Linux 6, Fedora
Posts: 445

Original Poster
Rep: Reputation: 37
Quote:
Originally Posted by grail View Post
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 ...
 
Old 07-26-2011, 04:25 PM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,250

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
This should tell you:
Code:
$ find --version
 
Old 07-26-2011, 04:34 PM   #9
DBabo
Member
 
Registered: Feb 2003
Distribution: Scientific Linux 6, Fedora
Posts: 445

Original Poster
Rep: Reputation: 37
Quote:
Originally Posted by grail View Post
This should tell you:
Code:
$ find --version
find: illegal option -- version
find: [-H | -L] path-list predicate-list
 
Old 07-26-2011, 05:55 PM   #10
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,606

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Thumbs up

Quote:
Originally Posted by DBabo View Post

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.
 
1 members found this post helpful.
Old 07-26-2011, 06:17 PM   #11
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by DBabo View Post
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
 
1 members found this post helpful.
Old 07-26-2011, 11:39 PM   #12
DBabo
Member
 
Registered: Feb 2003
Distribution: Scientific Linux 6, Fedora
Posts: 445

Original Poster
Rep: Reputation: 37
Quote:
Originally Posted by Tinkster View Post
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
 
Old 07-26-2011, 11:40 PM   #13
DBabo
Member
 
Registered: Feb 2003
Distribution: Scientific Linux 6, Fedora
Posts: 445

Original Poster
Rep: Reputation: 37
Quote:
Originally Posted by crts View Post
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?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
a2ps: cannot find file `c0419bt_.afm': No such file or directory rg3 Slackware 5 08-02-2009 04:11 PM
Quickly find the newest file in a directory yorkshiresteve Linux - General 2 02-15-2009 12:32 PM
How do i find the biggest file in my directory? anandv_1234 Linux - Newbie 11 12-21-2007 01:58 PM
find pattern in any file in directory sancho1980 Linux - Newbie 4 12-19-2006 09:14 AM
How do I use PHP to find a file's directory? a10waveracer Programming 3 09-06-2005 10:08 PM


All times are GMT -5. The time now is 06:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration