Web lists-archives.com

Re: An appropriate directory search tool?




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.

> > find . -type f | while read file ; do bash-function "$file"; done # avoid using exec
> 
> This one has a few minor bugs.  It will fail on filenames that contain
> newlines, or backslashes, or trailing whitespace, or leading whitespace.
> It can be corrected, although sadly the corrected version is a bit uglier.
> 
> find . -type f -print0 | while IFS= read -rd '' file; do bash-function "$file"; done

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).

> > find . -type f -name \*ly -printf '%TY-%Tm-%Td %TT %f\n' | cut --complement -b 20-30 | sort
> 
> This one looks like a variant of my "rlart" function:
> 
> rlart() {
>   find "${1:-.}" -type f -printf '%T@,%TY-%Tm-%Td,%TT,%p\0' |
>   sort -zn |
>   while IFS=, read -rd '' _ day time path; do
>     printf '%s %s %s\n' "$day" "${time%.*}" "$path"
>   done
> }
> 
> I give a detailed explanation of an earlier iteration of that one on
> <https://mywiki.wooledge.org/BashProgramming/03> for those who are
> interested in that sort of thing.  The explicit comma delimiters were
> added more recently, to avoid losing trailing whitespace.

Again, as you can see from -name, they're intended for particular sets
of files. Your considered version is better, so updated. However, I've
added back name so that just a set of source files are considered
(-name \*py might be a more obvious example for others) and I throw
away the leading directories.

Thanks once again for preening my bash constructs; much appreciated.

¹ I'm probably unusual in having a readonly .bash_history which
contains a handcrafted set of command paradigms. That's why some of
my commandlines might seem inordinately long, like hundreds of chars.

Cheers,
David.