LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 03-12-2012, 12:56 PM   #16
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,429

Rep: Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348

Try changing to
Code:
while read FILE; do find /root -path /root/tmp -prune -o -name $FILE -print; done < fnames.txt
 
Old 03-13-2012, 01:41 AM   #17
niiiro
Member
 
Registered: Feb 2010
Posts: 65

Original Poster
Rep: Reputation: 1
Yey! that works!

Thanks again dude.
 
Old 03-13-2012, 06:29 AM   #18
niiiro
Member
 
Registered: Feb 2010
Posts: 65

Original Poster
Rep: Reputation: 1
I'm sorry for popping up again with another question but I'm having another problem.

Every time I run that little script, it takes a word from the wordfile(fnames.txt) and performs a search. thing is, it'd take forever to search for the entire search values on a large DB servers.

My questions is, would it be possible to take the entire words(search values) and search for all at once?

I hope I explained myself correctly.


Thanks.
 
Old 03-13-2012, 08:54 AM   #19
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,429

Rep: Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348
You can use find with a construction like this
Code:
find /root -path /root/tmp -prune -o -name $FILE1 -o -name $FILE2 -o -name $FILE3 -print
It would take some shell coding to read in the filenames and build the find command to run.
Code:
#!/bin/bash

FILELIST=""

while read FILE; do
FILELIST=$FILELIST" -o -name "$FILE" -print" ;
done < fnames.txt

# Uncomment the next line for testing
#echo $FILELIST

find /root -path /root/tmp -prune $FILELIST
This would not be an infinitely scalable solution, as there is a finite limit on the number or characters allowed in a single command.

Now I wait for the shell coding gurus to say exactly how many ways this is wrong! :-)
 
Old 03-13-2012, 08:57 PM   #20
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
You could also multi-process ie run multiple copies of the above on different lists.
However, watch the system load... try using the nice cmd to lower priorities, but it will take longer.
Is speed an absolute requirement; if so why?

There's no quick/low load way of searching entire systems for arbitrary strings in arbitrary files.
You really need to know how your systems work and where likely candidates will exist.

Exactly why do you need to do this?
 
Old 03-14-2012, 03:56 AM   #21
niiiro
Member
 
Registered: Feb 2010
Posts: 65

Original Poster
Rep: Reputation: 1
allend, you're my hero, seriously. thank you very much - it worked perfectly.

chris, I had a 40tb server with tons of files, users needed to search for various files in the quickest way. thanks.


love this forum
 
  


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
[SOLVED] Find Text After String Search in Text File redir Linux - Newbie 12 08-02-2011 04:57 PM
[SOLVED] read a text file distrubute its contents on different text files magische_vogel Programming 13 02-26-2011 07:51 PM
Steps needed to convert multiple text files into one master text file jamtech Programming 5 10-08-2007 12:24 AM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 08:15 PM
linux 'find' to find text files subu_s Programming 2 12-02-2004 03:56 AM


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

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