- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: find a particular word in all the files
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
Discussions
Discussions
Forums
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
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
тАО02-21-2011 04:28 AM
тАО02-21-2011 04:28 AM
If that particular word is present in any of the files, i should know the file path.
Can you please guide me in this
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2011 04:39 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2011 04:40 AM - last edited on тАО09-02-2011 12:14 PM by Kevin_Paul
тАО02-21-2011 04:40 AM - last edited on тАО09-02-2011 12:14 PM by Kevin_Paul
Re: find a particular word in all the files
Use the find command in conjunction with grep:
find /start_dir -type f -exec grep -l "word" {} \;
http://h30499.www3.hp.com/t5/Languages-and-Scripting/grep-recursive/m-p/3863349#M17402
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2011 05:48 AM
тАО02-21-2011 05:48 AM
Re: find a particular word in all the files
If by "word" you mean what is generally though of as a word: a string of characters that match at the beginning or ending of a line, and consist of letters, digits and the underscore, then use the '-w option':
'grep -w myword'
Also, optimize your performance, *especially* if you want to search your entire server filesystem from '/':
# find / -type -f -exec grep -w myword {} +
Note the '+' terminator for the '-exec' arguments instead of the ';'. This causes multiple arguments to be aggregated and processed together with each instantiation of the exec'ed process rather than creating one process for every file.
If you want to see all matching lines and not just the filename (as with '-l'), do:
# find / -type f -exec grep -w myword {} /dev/null +
Lastly, if you only want to search beneath '/' but don't want to visit mountpoints; that is, you want to search directories like '/etc' and '/sbin' but not '/usr' or '/var', add the '-xdev' option:
# find / -xdev -type f -exec grep -w myword {} /dev/null +
Regards!
...JRF...
#
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2011 12:13 PM
тАО02-21-2011 12:13 PM
Re: find a particular word in all the files
find / -type f -exec grep -w myword {} /dev/null +
Typically you don't need that /dev/null trick with "+" since there are probably multiple files. And in any case find(1) specifically warns you not to add anything after the "{}":
find / -type f -exec grep -w myword /dev/null {} +