Our website would like to use cookies to store information on your computer. You may delete and block all cookies from this site, but parts of the site will not work as a result. Find out more about how we use cookies.

Login or Register

Powered by
Powered by Novacaster
linux 'find' command
by Bruce Ure at 12:35 06/08/05 (Forum::Technical Advice::General)
Not without trying, I have failed to find a way of asking:

find -name 'filename'

to only tell me about results in directories it can access by dint of the permissions of my account.

It returns for every directory it can't access, a line saying 'permission denied' along with the directory name.

I want to tell it OK, don't try and search it then, and don't bother telling me about it either.

However a scan of "man find" reveals once again that linux is not my favourite operating system, but not a lot else.


<< CafePress for the UK (again) Trivial, I thought. >>
View Comments (Threaded Mode) Printer Version
linux 'find' command Bruce Ure - 12:35 06/08/05
Re: linux 'find' command Bruce Ure - 12:45 06/08/05
and where the hell do I find sendmail logs?

Bloody command lines mutter mutter...

Re: linux 'find' command David Crowson - 13:28 06/08/05
find -name 'filename.ext' | grep -e 'Permission'


Re: linux 'find' command Hugo van der Sanden - 13:49 06/08/05
It has to test each path anyway, to discover the permissions; easiest is simply to ignore the errors:

find -name filename 2>/dev/null

On my system, mail logs are in /var/log/maillog.


Re: linux 'find' command David Crowson - 13:52 06/08/05
and I would have deleted my reply as the instant I pressed submit I realised it wouldn't work, but I didn't have the privs to do so.....


Re: linux 'find' command Hugo van der Sanden - 01:30 07/08/05
Well it's a discussion for a different thread, but in my experience there's a lot to be gained from seeing people's wrong answers as well.

Note that your answer would work fine if you add a '2>&1' to combine stdout and stderr.


Re: linux 'find' command Bruce Ure - 15:00 06/08/05
Ooooo, fab! Thanks. So the 2 means error lines? Ie. any line resulting in an error goes to /dev/null ?

What other numbers are there and are they part of the underlying os, or the find command, or something else completely?

I like Linux a bit more now.

Sigh. I'm so fickle.

Re: linux 'find' command Hugo van der Sanden - 01:28 07/08/05
Each process starts with three file descriptors ('fd's) set up: standard input, output and error streams (called 'stdin', 'stdout' and 'stderr' respectively) are always fd 0, fd 1 and fd 2 in that order, and for a simple shell command each of them is linked to the terminal.

By default, the shell applies '<' to fd 0 and '>' to fd 1, but you can override that by putting the numbers in. You can do funkier things like redirect one stream to another (eg find . 2>&1 | less lets you pipe the combined output and error streams into a pager).

Though the underlying file descriptors are supplied by the OS, these mechanisms for manipulating them are part of the shell - look at the 'bash' manpage for FMTYEWTK.


Re: linux 'find' command Bruce Ure - 18:08 08/08/05
Thanks Hugo, v. interesting.

Would you also know how to tail a file such that it doesn't report lines containing a certain string ("Message is frozen" at the end of a line)?

This is all new and scary though I can see the potential.

Re: linux 'find' command Hugo van der Sanden - 01:48 09/08/05
That's where you want to adapt Dave's solution:
  some command | grep -eF 'Message is frozen'

will print only those lines of the output that don't contain the specified string: the 'F' flag means "treat the argument as a fixed string rather than as a regular expression", and the 'e' flag means "print lines that don't match" (normal behaviour being "print lines that do match").

If it really needs to match only lines where that string appears at the end of the line, you need a regular expression:

  grep -e 'Message is frozen$'

.. in which the '$' matches end-of-line.

Be careful when extending this though: when the argument is a regular expression, various punctuation characters acquire special meanings, so you'll need to escape them (with a backslash) to match them literally.


Re: linux 'find' command Simon - 09:35 09/08/05
I think Hugo meant to say -v rather than -e to invert the match sense.

Just to add to what Hugo said - piping commands together is something I do all the time, especially with greps, when analysing logs. eg:

cat /var/log/httpd/access_log | grep -v my.ip.address | grep 'GET /some/path/script.cgi' | grep ' 500 ' > ~/my.output.log

... which would extract all the server error lines for script.cgi apart from those from my.ip.address and put them in a file in my home directory. Note that this could also be written as:

grep -v my.ip.address /var/log/httpd/access_log | grep 'GET /some/path/script.cgi' | grep ' 500 ' > ~/my.output.log

... to avoid the unnecessary cat.

Re: linux 'find' command Hugo van der Sanden - 18:29 09/08/05
I think Hugo meant to say -v rather than -e to invert the match sense.

Oops, yes.


Re: linux 'find' command Rob Larsen - 18:55 04/08/06
locate can be better for this type of thing


locate sendmail.cf


Re: linux 'find' command Simon - 09:21 07/08/06
Hi Rob, how's it going? Not heard from you in a while.