I've historically performed something like:
find . 2>/dev/null | xargs grep -i something_to_find 2>/dev/null
If my pwd
is barfoo (/foo/bar/baz/foofoo/foobar/foobaz/barfoo
) it finds matches. However, if I cd
to /foo
, it no longer finds the matches.
Conditions:
- permissions are all 775
- the directories are not symbolic links
- they are all on the same file system / server
So I'm curious if there is a default -maxdepth
that is applied to find, or are there other constraints as to why this would not work?
Additional Info:
Some great comments have been posted. Here is some additional info:
- this is for GNU, not POSIX
find --version
: GNU find version 4.2.27grep --version
: (GNU grep) 2.5.1xargs --version
: GNU xargs version 4.2.27- removing the redirection of STDERR has no bearing on the result, or lack thereof
- the path to the files in
barfoo
(known to work) do not have spaces, however files in other directories in/foo/bar
may have spaces; though, I don't see how that would be problematic - I realize I wasn't specific on the path, but these are all well-named directories, not to be confused with any devices
Interesting Finding:
The first doesn't work, but the second does:
find . -type f | xargs grep -i something_to_find
find . -type f -name "*.ext" | xargs grep -i something_to_find
Even odder is that -name "*.*"
does not work, the file extension has to be given; which could be problematic when searching for something.
I'm wondering if there is termination after a max error count, or maximum buffer size. I know there are a lot of files in these directories, but the fact it works when specifying the filetype (limiting results) is interesting.
-maxdepth
, but there could be a filesystem limit on the length of pathnames. How long are the real pathnames involved?2>/dev/null
if you want to have any chance of finding out what's going on. Edit your question to add the error messages.