- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to search srings in OS?
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
11-09-2006 02:21 AM
11-09-2006 02:21 AM
I want to find a file with strings "hello" in it.
how can I do?use find command?thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2006 02:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2006 02:25 AM
11-09-2006 02:25 AM
Re: How to search srings in OS?
cd /dir
grep -i hello *
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2006 02:28 AM
11-09-2006 02:28 AM
Re: How to search srings in OS?
find / -exec grep -l "hello" {} \;
find
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
11-09-2006 02:33 AM
11-09-2006 02:33 AM
Re: How to search srings in OS?
Please read:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=629412
The -type f restrict to files only, rather than for example directories etc.
Note: This can take a while to run and return some strange results, like searching binaries etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2006 02:41 AM
11-09-2006 02:41 AM
Re: How to search srings in OS?
As noted, you don't want to search directories, and you don't want to search binary files. Youc can use this approach though:
# 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
11-09-2006 03:11 AM
11-09-2006 03:11 AM
Re: How to search srings in OS?
passing grep to find in back quotes ` `
grep -n "hello" `find /full/path/* -type f -print`
where n is the line number.
If argument list is too long,
then loop by directory.
Let me know if you want to know how.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2006 01:10 PM
11-09-2006 01:10 PM
Re: How to search srings in OS?
how can I do
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2006 01:26 PM
11-09-2006 01:26 PM
Re: How to search srings in OS?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2006 01:48 PM
11-09-2006 01:48 PM
Re: How to search srings in OS?
You can specify multiple directories to search when you use 'find':
# find /usr /var /opt -xdev -type f -print
The use of '-xdev' prevents 'find' from traversing mountpoints. This is most useful if you want to search the root directory ('/') but *not* mountpoints like '/usr', '/var' etc.
Regards!
...JRF...