[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: An appropriate directory search tool?

On Tue 30 Oct 2018 at 09:52:52 (-0500), David Wright wrote:
> On Fri 19 Oct 2018 at 12:03:42 (-0400), Greg Wooledge wrote:
> > On Fri, Oct 19, 2018 at 10:48:42AM -0500, David Wright wrote:
> > > find . -type f -exec chmod a-wx {} \;
> > 
> > For this one, you probably want to replace \; with + to get the efficiency
> > boost, which would be pretty significant here.  You probably wrote this
> > one a long time ago.
> You're dead right. It could even have been copied straight from Unix
> Power Tools 1st ed. And, of course, with the other example
> find . -type f -exec file {} \; | less
> it can make a huge difference to the number of "find: ‘file’
> terminated by signal 13" messages if you lose interest and quit
> out of less.


> Updated. I'm more careful in writing my bash functions than this
> commandline¹ stuff where the filename population tends to be
> more restricted (ie I generated them).

… and so I was running my eyes over my .bashrc file to see if there
were any similar constructions that had survived over the years and
could do with updating. In doing so, I came across examples where
a little extra thought is required:

    find "$@" -depth -xdev -type d -empty -ok rmdir {} \;
    find "$@" -depth -xdev -type d -empty -print -exec rmdir {} \;

Using + in the second example won't work correctly.

There's a warning in   man find   about the potential of + to
short-circuit running all the commands in case of error, but
perhaps it should also warn of the dangers of mixing + and -depth.


Reply to: