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
01-04-2007 05:12 AM
01-04-2007 05:12 AM
Find
Hi all,
Find a particular file a unknown path . this I can do using
Find / -name “name of the file”
Also I would like to find a particular string in that specified files.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2007 05:16 AM
01-04-2007 05:16 AM
Re: Find
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2007 05:27 AM
01-04-2007 05:27 AM
Re: Find
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2007 09:21 AM
01-04-2007 09:21 AM
Re: Find
Also remember this will take considerably longtime if you are using from root (/),
Also you can use :
# ls -lR | awk '{print $9}' | xargs grep -l "expr"
This will give you the file names with the matching string,
Cheers,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2007 09:24 AM
01-04-2007 09:24 AM
Re: Find
In the above example, "expr" is the 'string' that you are looking for in all the files recursively.
Cheers,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2007 09:55 AM
01-04-2007 09:55 AM
Re: Find
If you are searching for files in the root ('/') directory, you would be advised to add '-xdev' so that you do not cross mountpoints.
Secondly, either pipe 'find's output to 'xargs' or terminate the '-exec' argument with a plus sign ('+') rather than a semicolon (';'). Using 'xargs' or using a plus sign character greatly improves performance because multiple arguments are processes instead of spawning a new process for every, single argument.
Thus:
# find / -xdev -type f -name "*my*" -exec grep pattern {} /dev/null \+
Prior to 11i, you use a '\;' instead of '\+' to terminate the 'find' and suffer the performance penality.
Otherwise:
# find / -xdev -type f -name "*my*" | xargs grep pattern
Note the addition of the '/dev/null' to the form using '-exec' causes the matching filename to be printed for positive 'grep's.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2007 08:16 PM
01-04-2007 08:16 PM
Re: Find
to search string "hello world" only in text files including subdirectories:
grep "hello world" $(find ./ -type f |xargs file|grep text|cut -d ':' -f1)
./ = start directory
-type f = only files
grep text = only text files
cut -d ':' -f1 = name of the file
this will avoid to look into other files than text i.e.: binary, links and so on.
HTH,
Art