LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-02-2012, 02:19 AM   #1
akeka
Member
 
Registered: May 2012
Posts: 39

Rep: Reputation: Disabled
Help with find files


Hi,

I want to search multiple file name in multiple location

Can I do it in one command ?

Thanks for the help
 
Old 10-02-2012, 02:29 AM   #2
kabamaru
Member
 
Registered: Dec 2011
Location: Greece
Distribution: Slackware
Posts: 276

Rep: Reputation: 134Reputation: 134
Code:
find PATH_1 PATH_2 PATH_N -name NAME_A -o -name NAME_B -o -name NAME_C
 
1 members found this post helpful.
Old 10-02-2012, 02:33 AM   #3
akeka
Member
 
Registered: May 2012
Posts: 39

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by kabamaru View Post
Code:
find PATH_1 PATH_2 PATH_N -name NAME_A -o -name NAME_B -o -name NAME_C
Thank you for the reply

Can I use input file that contain list of the files that I want to search ?

Since the files are quite many

Thanks again
 
Old 10-02-2012, 02:44 AM   #4
kabamaru
Member
 
Registered: Dec 2011
Location: Greece
Distribution: Slackware
Posts: 276

Rep: Reputation: 134Reputation: 134
Code:
grep 'SEARCH_STRING' INPUT_FILE
grep uses basic regular expressions, and with the -E switch, it uses extended regular expressions.
 
Old 10-02-2012, 02:49 AM   #5
akeka
Member
 
Registered: May 2012
Posts: 39

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by kabamaru View Post
Code:
grep 'SEARCH_STRING' INPUT_FILE
grep uses basic regular expressions, and with the -E switch, it uses extended regular expressions.
Can you please be more specific ?

Let say

I've file named list that contain the list of files that I want to search

Quote:
file1
file2
file3
file4
file5
...
Thanks
 
Old 10-02-2012, 03:04 AM   #6
kabamaru
Member
 
Registered: Dec 2011
Location: Greece
Distribution: Slackware
Posts: 276

Rep: Reputation: 134Reputation: 134
If for example, you want to find file with name "file1" in a list named "my_list.txt",

Code:
grep 'SEARCH_STRING' INPUT_FILE
translates to

Code:
grep 'file1' my_list.txt
That said, the program find generates a list that looks more like this:

Code:
./file1
./path1/path2/file_2
....... etc.
So you could use

Code:
grep '/file1$' my_list.txt
which will search for lines that end ($) with '/file1'.
 
Old 10-02-2012, 03:37 AM   #7
akeka
Member
 
Registered: May 2012
Posts: 39

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by kabamaru View Post
If for example, you want to find file with name "file1" in a list named "my_list.txt",

Code:
grep 'SEARCH_STRING' INPUT_FILE
translates to

Code:
grep 'file1' my_list.txt
That said, the program find generates a list that looks more like this:

Code:
./file1
./path1/path2/file_2
....... etc.
So you could use

Code:
grep '/file1$' my_list.txt
which will search for lines that end ($) with '/file1'.
Hmmm, can I combine the grep command with find command for my needs ?
 
Old 10-02-2012, 03:57 AM   #8
kabamaru
Member
 
Registered: Dec 2011
Location: Greece
Distribution: Slackware
Posts: 276

Rep: Reputation: 134Reputation: 134
Quote:
Originally Posted by akeka View Post
Hmmm, can I combine the grep command with find command for my needs ?
You can pipe them. Find's output becomes grep's input.

Code:
find_command | grep_command
 
Old 10-03-2012, 01:50 AM   #9
akeka
Member
 
Registered: May 2012
Posts: 39

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by kabamaru View Post
You can pipe them. Find's output becomes grep's input.

Code:
find_command | grep_command
Hi kabamaru,

Thank you for the reply but I still don't understand how the find and grep command on your example
 
Old 10-03-2012, 02:46 AM   #10
kooru
Senior Member
 
Registered: Sep 2012
Posts: 1,385

Rep: Reputation: 275Reputation: 275Reputation: 275
Hi,

if you have a listfile.txt with the list of files that you want find on multiple path, you can do this:


Code:
while read line
do
        echo "Serching $line:"
        find PATH1 PATH2 PATH3 -name $line
done < listfile.txt
 
Old 10-03-2012, 02:59 AM   #11
kabamaru
Member
 
Registered: Dec 2011
Location: Greece
Distribution: Slackware
Posts: 276

Rep: Reputation: 134Reputation: 134
Simple example of find. Search current directory for file (or directory or whatever) named "mycv".
Code:
find . -name mycv
Another example of find:
Code:
find /home/bob /mnt/documents -type f -name "*.txt" -o -name "*.rtf"
Which means: search /home/bob and /mnt/documents for files (-type f) with name (-name) that ends in .txt or (-o) .rtf. To make this case insensitive e.g. to match (txt,rtf,TXT,RTF), use -iname instead of -name.

Output:
Code:
./home/bob/j.txt
./home/bob/formal.txt
./home/bob/folder1/z.txt
./mnt/documents/a_form.rtf
./mnt/documents/web/fun/links.txt
./mnt/documents/backup/b_form.rtf
...
Examle of grep + find:
Code:
find /home/bob /mnt/documents -name "*.txt" -o -name "*.rtf" | grep 'form'
Output:
Code:
./home/bob/formal.txt
./mnt/documents/a_form.rtf
./mnt/documents/backup/b_form.rtf
Grep got the output from find and displayed the lines that contained the string "form"

All that said, the tools you'll choose and the way you'll use them really depends on the specifics of the task at hand.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
find hidden files from wild card path using 'find' nagendrar Linux - Newbie 5 10-13-2011 10:48 PM
linux find to find files with multiple patterns subu_s Programming 6 12-15-2010 12:15 AM
Find/grep/wc command to find matching files, print filename and word count dbasch Linux - Newbie 10 09-14-2009 05:55 PM
Single find command to find multiple files? thok Linux - Newbie 7 01-31-2009 04:45 PM
Is there a way to find recently created/edited files without using find? BrianK Linux - General 2 10-15-2007 09:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:06 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
Open Source Consulting | Domain Registration