Suddenly for me the “find” command is returning mostly a list of “Is a directory” errors.
For example:
cd /tmp
mkdir a
cd a
mkdir b
find . -exec grep foo {} ;
grep: .: Is a directory
grep: ./b: Is a directory
I would expect “find” to return nothing in this case. Needless to say this in unhelpful when searching a large directory tree. Any help would be appreciated.
More Info:
:/tmp/a> which find
/usr/bin/find
:/tmp/a> ls -l /usr/bin/find
-rwxr-xr-x 1 root root 180904 Dec 7 08:01 /usr/bin/find
:/tmp/a> ls -l /bin/find
lrwxrwxrwx 1 root root 13 Mar 1 13:14 /bin/find -> /usr/bin/find
uname -a Linux lap1.site 3.4.28-2.20-desktop #1 SMP PREEMPT Tue Jan 29 16:51:37 UTC 2013 (143156b) x86_64 x86_64 x86_64 GNU/Linux
>
> Suddenly for me the “find” command is returning mostly a list of “Is a
> directory” errors.
>
> For example:
> cd /tmp
> mkdir a
> cd a
> mkdir b
> find . -exec grep foo {} ;
> grep: .: Is a directory
> grep: ./b: Is a directory
>
> I would expect “find” to return nothing in this case. Needless to say
> this in unhelpful when searching a large directory tree. Any help would
> be appreciated.
>
> More Info:
> :/tmp/a> which find
> /usr/bin/find
> :/tmp/a> ls -l /usr/bin/find
> -rwxr-xr-x 1 root root 180904 Dec 7 08:01 /usr/bin/find
> :/tmp/a> ls -l /bin/find
> lrwxrwxrwx 1 root root 13 Mar 1 13:14 /bin/find -> /usr/bin/find
>
> uname -a Linux lap1.site 3.4.28-2.20-desktop #1 SMP PREEMPT Tue Jan 29
> 16:51:37 UTC 2013 (143156b) x86_64 x86_64 x86_64 GNU/Linux
>
>
‘find’ finds everything: files, directories, symlinks, anything that can
exist in the filesystem. If you only want to look at files, you need to
tell it so.
This is only a warning from grep. And yes, that warning wasn’t always there which maybe an anoying change, But as you found out, even in earlier times you executed the grep on directories, only grep did not inform you of the fact.
And it is always (was also in the past) a good thing to think about what find does when you type a find command.
BTW read the man page of grep. That shows that another posibility is to use -d skip with grep. There are always many solutions to the same question in Unix/Linux.
But I think that letting find only execute grep on things that matter is the best solution because it may prevent many executions of grep. Think of all the needless executions of grep you did in those ~20 years! That is the real problem!