- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- A recursive grep from root directory doesnt work a...
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
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
тАО11-13-2009 11:02 AM
тАО11-13-2009 11:02 AM
I do a recursive grep (piped from a find) on the entire file system (from / downward). I do:
find / -type f 2>>1err.txt -print |xargs grep mystring 2>>2err.txt
It simply doesnt find the expected string. While I know at least some files (with permission to read) where the string exists (under a certain directory). When I do:
find /certain_directory/ -type f 2>>1err.txt -print |xargs grep mystring 2>>2err.txt
It will find the string in the expected file in a sub directory of certain_directory.
The 2>> is to avoid the messages on files that my user doesnt have permission to read.
What can be the reason? If its a symbolic link permission problem how can I display or detect it?
ItтАЩs a POSIX shell if IтАЩm not wrong.
Thanks for the answers.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2009 11:24 AM
тАО11-13-2009 11:24 AM
Re: A recursive grep from root directory doesnt work as expected
I'm afraid, the problem is in xargs format.
Try the following:
find / -type f -exec grep -l mystring {} \;
This works, tested and confirmed.
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2009 12:13 PM
тАО11-13-2009 12:13 PM
Re: A recursive grep from root directory doesnt work as expected
Using -exec instead of xargs will create a child process for each output string from the find command to the grep. This is very disadvantageous resources wise.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2009 12:27 PM
тАО11-13-2009 12:27 PM
Solution> Using -exec instead of xargs will create a child process for each output string from the find command to the grep. This is very disadvantageous resources wise.
That's true _if_ you terminate the '-exec' argument with a semicolon. If you use a '+' as a terminator, multiple arguments are bundled together and passed en mass to the process spawned --- the equivalent of 'xargs'. Thus:
# find / -type f -exec grep -l mystring {} +
...is very efficient from the standpoint of the spawning of processes.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2009 06:19 PM
тАО11-13-2009 06:19 PM
Re: A recursive grep from root directory doesnt work as expected
It should but it may take forever.
>If it's a symbolic link permission problem how can I display or detect it?
Symlink permissions are ignored.
find(1) won't follow symlinks unless you use -follow. But if you are starting in /, that shouldn't matter.
>Victor: the problem is in xargs format.
What's wrong with it? yaron1 had it working with a different find(1).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-16-2009 11:00 AM
тАО11-16-2009 11:00 AM
Re: A recursive grep from root directory doesnt work as expected
I would check the collected output in the files ?err.txt.
- Does one of the parent directories contain names including spaces? The grep will not get them correctly!
- Maybe the 'find /' lasts forever or you did specify other find-options (-xdev?) which skip /certain_directory ?
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-16-2009 12:02 PM
тАО11-16-2009 12:02 PM
Re: A recursive grep from root directory doesnt work as expected
> contain names including spaces? The grep
> will not get them correctly!
Which "grep"? Why?
rux # uname -a
HP-UX rux B.11.31 U ia64 1678555272 unlimited-user license
rux # ls -l
total 0
rux # pwd
/root/itrc/ro ot
rux # mkdir 'a b'
rux # echo fred > 'a b/c d'
rux # find . -type f -exec grep fred {} \; -exec ls -l {} \;
fred
-rw-r--r-- 1 root sys 5 Nov 16 07:54 ./a b/c d
Some things actually _do_ work, even with
messy file names. Perhaps "find" is smarter
than you think.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-16-2009 01:10 PM
тАО11-16-2009 01:10 PM
Re: A recursive grep from root directory doesnt work as expected
yaron1 used find ... | xargs
Do you try this?
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-16-2009 01:32 PM
тАО11-16-2009 01:32 PM
Re: A recursive grep from root directory doesnt work as expected
Yes, and someone else didn't, and you didn't
say what you were talking about (other than
"The grep [...]").
> Do you try this?
Why would I? "find -exec" normally does what
I need to do, without adding the
complications of xargs.