Re: head, recursively through file tree?

From: Stephane CHAZELAS (this.address_at_is.invalid)
Date: 07/14/04


Date: 14 Jul 2004 07:51:45 GMT

2004-07-14, 01:30(+00), foo:
[...]
>> statements in the FAQ shipped with it about its advantages are
>> wrong (especially the performance one once you've read such an
>
> I wasn't too sure about the advantages either. Would you mind correcting or
> clarifying the incorrect statements?

| Nevertheless, in comparison to using find -exec, key
| advantages of using "For each File" are as follows.
|
| * Performance -- system resources are better utilized.

How come? in the recursive way, ff even uses find (in a
non-reliable way).

| * Flexibility -- the user can perform complex tasks without
| having to write a separate script.

???

What's the problem with running a shell or perl inline script
with find -exec ? That's even more flexible as you can chose
the interpreter you like.

| * Simplicity -- saves the user time and effort while
| increasing their productivity.

What's so difficult with "find -exec"?

| Performance of execution.
|
| For every file it encounters, find -exec forks a separate
| child-process to execute the user's commands. On a large input
| size, this behavior yields poor performance. In contrast, this
| tool employs only one process (analogous to xargs) to execute
| the user's commands. Thus it uses less system resources and
| yields better performance.

No, the shell forks a process for every command it runs unless
it is builtin. xargs saves forks (and overall execs) by
processing several files at the same time with one single
command ("rm file1 file2" instead of "rm file1" then "rm
file2"), ff doesn't seem to do that.

>> awfull script like: ff.capitalize).
>>
>
> That script really is quite horrible, but I think it's only meant to serve
> as an example. Perhaps the author should consider rewriting it or remove
> such poorly written examples from the package.

The problem is that rewriting it would reveal the need for awk
or perl so would raise the question: why not having written the
whole thing in a real programming language?

With zsh, to capitalise files recursively:

zmv '(**/)(*)' '$1/${(C)2}'

or:

for f (./**/*(NDod)) mv $f $f:h/${(C)f:t}

(with no limitation on the filenames).

-- 
Stephane


Relevant Pages