LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-01-2006, 06:33 PM   #1
thekillerbean
Member
 
Registered: Jan 2002
Location: Melbourne, Australia
Distribution: Ubuntu 22.04 (Jammy)
Posts: 92

Rep: Reputation: 16
Problems searching entire files system.


Hello all.

I'm trying to search for a particular entry in a file somewhere on my system and I noticed that 'find' appears stuck on a particular file - /proc/kmsg.

I used the following syntax to search for my text:
Code:
find / -type f -exec grep -iH searchtxt {} \; > ~/foundit 2> /dev/null &
The process has now been running for > 72hrs and a listing of 'ps -ef' reveals the following related processes for the last 21 hrs:
Code:
... find / -type f -exec grep -iH searchtxt {} ;
... grep -iH searchtxt /proc/kmsg
How can I make it search without getting hung on a file?

tia,
kb.
 
Old 01-02-2006, 12:32 AM   #2
loonix
Member
 
Registered: Aug 2003
Location: Sydney Australia
Distribution: CentOS/archlinux
Posts: 40

Rep: Reputation: 16
On all pc's i have access to I add the following bash script I whipped up. Short, simple and REAL handy.
Code:
#!/bin/bash
if [ $# -eq 0 ]
then
        echo "Usage: search [-l] string"
else
        find . -path "/proc" -prune -o -path "/dev" -prune -o -type f -print0 | xargs -0 grep -I $1 $2
fi

The optional -l flag is the standard grep -l flag. Just return the filenames or return the matches aswell as the filenames



Regards

lunix_aus
( Mick Pollard )
** Modified code as per 'thekillerbean' **

Last edited by loonix; 01-04-2006 at 12:07 AM.
 
Old 01-02-2006, 10:36 AM   #3
Munkur
LQ Newbie
 
Registered: Sep 2003
Location: Sweden
Distribution: Gentoo
Posts: 18

Rep: Reputation: 0
I do not know why find appears to be stuck. I just wanted to tell LQ readers about Beagle, a program one can use to search file systems:

http://beaglewiki.org/Main_Page

It resembles Google Desktop somewhat.
 
Old 01-02-2006, 11:20 AM   #4
risu
LQ Newbie
 
Registered: Feb 2005
Location: Helsinki, Finland
Posts: 19

Rep: Reputation: 2
Quote:
Originally Posted by loonix
On all pc's i have access to I add the following bash script I whipped up. Short, simple and REAL handy.
Code:
#!/bin/bash
if [ $# -eq 0 ]
then
        echo "Usage: search [-l] string"
else
        find . -name "/proc" -prune -o -name "/dev" -prune -type f -print0 | xargs -0 grep -I $1 $2
fi

The optional -l flag is the standard grep -l flag. Just return the filenames or return the matches aswell as the filenames



Regards

lunix_aus
( Mick Pollard )
I had to correct a few typos to find what I wanted: -name (twice) should be -path and -type should be preceded by another -o. Now it's REAL handy
 
Old 01-02-2006, 01:38 PM   #5
axobeauvi
Member
 
Registered: Apr 2003
Posts: 128

Rep: Reputation: 16
you may want to try locate
it builds a db of all the files on your system
then you can just locate file_name
 
Old 01-02-2006, 03:13 PM   #6
halvy
Member
 
Registered: Aug 2005
Location: Anchorage, Alaska (soon EU, hopefully)
Distribution: Anything NOT SystemD (ie. M$) related.
Posts: 918

Rep: Reputation: 42
locate is good but you need to make sure it is kept updated with cron or you have to continueally 'updatedb' whenever you add/delete anything.

also you need to make sure you have all the partitians mounted that you want 'considered' in the index (and not stuff like archives and backups) which may be repetitious and time consuming to index.

the locate and updatedb config files are your friends.
 
Old 01-02-2006, 05:04 PM   #7
Dr_P_Ross
Member
 
Registered: Nov 2003
Location: Edinburgh, UK
Distribution: Arch
Posts: 43

Rep: Reputation: 18
The reason why the find command hung when searching for some text within /proc/kmsg
is that this is a special file, mainly used by klogd to access system messages. A read
of /proc/kmsg will never end -- you can read more about it in the kernel documentation
in (probably) /usr/src/linux/Documentation/oops-tracing.txt if you have the kernel source installed.

Because /proc contains special files that only provide information about, and control of, processes
and devices, you probably don't want to even bother looking at those files when searching your filesystem for files that contain some text of interest to you. So the simplest remedy is to use find's "-prune" option to omit that whole filesystem subtree from the search.

Cheers,

Peter Ross
 
Old 01-02-2006, 05:32 PM   #8
loonix
Member
 
Registered: Aug 2003
Location: Sydney Australia
Distribution: CentOS/archlinux
Posts: 40

Rep: Reputation: 16
Quote:
Originally Posted by risu
I had to correct a few typos to find what I wanted: -name (twice) should be -path and -type should be preceded by another -o. Now it's REAL handy
Glad it has helped you out. I use it all the time. What I pasted above is exactly how I use it on my system and it works fine. Can you post what mods you did. i would be interested seeing it.


Cheers
lunix_aus
( Mick Pollard )
 
Old 01-02-2006, 11:12 PM   #9
thekillerbean
Member
 
Registered: Jan 2002
Location: Melbourne, Australia
Distribution: Ubuntu 22.04 (Jammy)
Posts: 92

Original Poster
Rep: Reputation: 16
Thank you all so much. My sanity has returned!

kb.
 
Old 01-03-2006, 11:34 PM   #10
thekillerbean
Member
 
Registered: Jan 2002
Location: Melbourne, Australia
Distribution: Ubuntu 22.04 (Jammy)
Posts: 92

Original Poster
Rep: Reputation: 16
Unfortunately, it appears that the solution above, really a modified version of the solution:

Code:
find . -name "/proc" -prune -o -name "/dev" -prune -type f -exec grep -iH searchtxt {} \; \
     > ~/foundit 2> /dev/null &
still resulted in a hung find process with grep showing:

Code:
grep -iH searchtxt /proc/kmsg
I'll create the script you have above and leave it running overnight.
 
Old 01-03-2006, 11:42 PM   #11
thekillerbean
Member
 
Registered: Jan 2002
Location: Melbourne, Australia
Distribution: Ubuntu 22.04 (Jammy)
Posts: 92

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by risu
I had to correct a few typos to find what I wanted: -name (twice) should be -path and -type should be preceded by another -o. Now it's REAL handy


Dang it, I just saw this response after posting. Now I know why it did not work!


To loonix:

Please modify your original post so that others may benefit from a properly formated find command!

All's well that ends well anyway.

Thanks.
 
Old 01-04-2006, 12:10 AM   #12
loonix
Member
 
Registered: Aug 2003
Location: Sydney Australia
Distribution: CentOS/archlinux
Posts: 40

Rep: Reputation: 16
Quote:
Originally Posted by axobeauvi
you may want to try locate
it builds a db of all the files on your system
then you can just locate file_name
locate will not do what was originally asked here. Locate will find a file with a match in the "filename"
What this thread is about is searching for a string INSIDE of files.
 
Old 02-03-2006, 08:29 AM   #13
risu
LQ Newbie
 
Registered: Feb 2005
Location: Helsinki, Finland
Posts: 19

Rep: Reputation: 2
Better late than never, here is my modified version of the search script:

#!/bin/bash
if [ $# -eq 0 ]
then
echo "Usage: search [-l] string"
else
find . -path "/proc" -prune -o -path "/dev" -prune -o -type f -print0 | xargs -0 grep -I $1 $2
fi
 
  


Reply



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
How to Reconfigure the entire system...... manojpillai Fedora 5 12-18-2004 06:50 PM
Updating entire system? Eklipz Slackware 9 12-12-2004 04:11 PM
How to backup entire system without shutting down andrewjschmidt Linux - General 6 06-01-2004 06:01 PM
Backup entire system with tar sln Linux - General 2 04-30-2004 03:32 AM
How can I backup my entire system? TheDirtyPenguin Linux - Software 5 03-16-2004 08:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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