- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Google for Unix System
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2006 10:56 AM
08-02-2006 10:56 AM
cd /
grep -i "string" */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/* 2>/dev/null
Does anybody know a better way to search the whole system for certain string in a file, when the file in which the string is placed is unknown ...
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2006 11:13 AM
08-02-2006 11:13 AM
SolutionIf you truly want to search every file in a directory and 'grep' for a paricular string, I'd do:
# find / -type f | xargs grep "Hunki"
This will find *files* with the string "Hunki" somewhere within and report both the filename and every matching instance.
One of the problems with this, however, is that you will search binary files along with ASCII (text) files. Searching binary files is fruitless.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2006 11:29 AM
08-02-2006 11:29 AM
Re: Google for Unix System
Actually, we can rather quickly circumvent searching the non-ASCII (binary) files :
# cat ./google
#/usr/bin/sh
typeset DIR=$1
typeset PAT=$2
find ${DIR} -type f | while read FILE
do
[ `file ${FILE}|grep -c ascii` -eq 0 ] && continue
grep "$PAT" ${FILE} /dev/null
done
...run the script passing the directory ($1) that you want to search and the pattern ($2) you want to find. For example:
./google /etc/rc.config.d ROUTE
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2006 01:45 PM
08-02-2006 01:45 PM
Re: Google for Unix System
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2006 01:48 PM
08-02-2006 01:48 PM
Re: Google for Unix System
If you want to search your entire system then just use / for your directory. That will cause the find command to traverse the entire system.
Just be wanred that this MAY slow your system as find can be CPU intensive.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2006 01:51 PM
08-02-2006 01:51 PM
Re: Google for Unix System
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2006 04:24 PM
08-02-2006 04:24 PM
Re: Google for Unix System
I urge caution.
It can only take a few find processes searching from root to bring a powerful system to its needs.
Going through every file on a system can consume a lot of resources. Its better to search the file systems most likely to contain the information individually.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2006 04:34 PM
08-02-2006 04:34 PM
Re: Google for Unix System
running the search on all files on the file system can be very time consuming and is also not recommended on a production system.
you would not want to search /dev/, /tmp/ and /stand for example!
You may also restrict the search on certain type of files only.
please check
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2006 08:15 PM
08-02-2006 08:15 PM
Re: Google for Unix System
As told above it is not recomended to serach string from the root filesystem. Eventhough if you are going for that make sure sufiicient memory is present.
Cheers
Deepak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2007 04:31 AM
03-01-2007 04:31 AM
Re: Google for Unix System
I dont want to search *log* / binaries while searching.
thanks,
hunki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2007 04:49 AM
03-01-2007 04:49 AM
Re: Google for Unix System
# cat ./google
#/usr/bin/sh
typeset DIR=$1
typeset PAT=$2
find ${DIR} -type f ! -name "*log" | while read FILE
do
[ `file ${FILE}|grep -c ascii` -eq 0 ] && continue
grep "$PAT" ${FILE} /dev/null
done
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2007 04:52 AM
03-01-2007 04:52 AM
Re: Google for Unix System
! -name "*log*"
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2007 04:59 AM
03-01-2007 04:59 AM
Re: Google for Unix System
If I understand correctly, you don't want to search either binary files *or* files with the string "log" in their name. If that is corerct, use this modified version of my original script:
# cat ./google
#/usr/bin/sh
typeset DIR=$1
typeset PAT=$2
find ${DIR} -type f -a ! -name "*log*" | while read FILE
do
[ `file ${FILE}|grep -c ascii` -eq 0 ] && continue
grep "$PAT" ${FILE} /dev/null
done
exit 0
...run the script passing the directory ($1) that you want to search and the pattern ($2) you want to find. For example:
./google /path pattern
Regards!
...JRF...