Execute command on one file per directory
Execute command on one file per directory
am 29.11.2007 15:27:03 von mathieu.malaterre
Could anyone tell me what is wrong with the following:
Print one filename per directory (ok):
find /images/ -type d -exec find {} -maxdepth 1 -type f -print -quit
\;
Print one basename per directory:
find /images/ -type d -exec find {} -maxdepth 1 -type f -print -quit -
exec basename {} png \; \;
Thanks
Re: Execute command on one file per directory
am 29.11.2007 16:41:59 von Icarus Sparry
On Thu, 29 Nov 2007 06:27:03 -0800, mathieu wrote:
> Could anyone tell me what is wrong with the following:
>
> Print one filename per directory (ok):
>
> find /images/ -type d -exec find {} -maxdepth 1 -type f -print -quit \;
>
> Print one basename per directory:
>
> find /images/ -type d -exec find {} -maxdepth 1 -type f -print -quit -
> exec basename {} png \; \;
>
> Thanks
Lots of things. how does the first find know that it needs to skip over
the first semicolon and use the second one?
How does the first find know it should substitute for the first {}, but
not the second?
If you "quit", why do you expect to "exec" later?
I suggest something more along the lines of
find /images -type d -exec \
sh 'find $1 -maxdepth 1 -type f -exec basename {\} png \;' {} {} \;
if this needs to go on a single line. Otherwise write one shellscript
that given a list of directorynames does whatever you want in those
directories, and then invoke that from find.
Re: Execute command on one file per directory
am 30.11.2007 10:42:45 von mathieu.malaterre
On Nov 29, 4:41 pm, Icarus Sparry wrote:
> On Thu, 29 Nov 2007 06:27:03 -0800, mathieu wrote:
> > Could anyone tell me what is wrong with the following:
>
> > Print one filename per directory (ok):
>
> > find /images/ -type d -exec find {} -maxdepth 1 -type f -print -quit \;
>
> > Print one basename per directory:
>
> > find /images/ -type d -exec find {} -maxdepth 1 -type f -print -quit -
> > exec basename {} png \; \;
>
> > Thanks
>
> Lots of things. how does the first find know that it needs to skip over
> the first semicolon and use the second one?
>
> How does the first find know it should substitute for the first {}, but
> not the second?
>
> If you "quit", why do you expect to "exec" later?
Because I want only *one* file per directory. Without the quit it is
not working...
but indeed with the -quit -exec does not work anymore
-Mathieu
Re: Execute command on one file per directory
am 01.12.2007 18:58:39 von Icarus Sparry
On Fri, 30 Nov 2007 01:42:45 -0800, mathieu wrote:
> On Nov 29, 4:41 pm, Icarus Sparry wrote:
>> On Thu, 29 Nov 2007 06:27:03 -0800, mathieu wrote:
>> > Could anyone tell me what is wrong with the following:
>>
>> > Print one filename per directory (ok):
>>
>> > find /images/ -type d -exec find {} -maxdepth 1 -type f -print -quit
>> > \;
>>
>> > Print one basename per directory:
>>
>> > find /images/ -type d -exec find {} -maxdepth 1 -type f -print -quit
>> > - exec basename {} png \; \;
>>
>> > Thanks
>>
>> Lots of things. how does the first find know that it needs to skip over
>> the first semicolon and use the second one?
>>
>> How does the first find know it should substitute for the first {}, but
>> not the second?
>>
>> If you "quit", why do you expect to "exec" later?
>
> Because I want only *one* file per directory. Without the quit it is not
> working...
> but indeed with the -quit -exec does not work anymore
>
> -Mathieu
Let me try and explain another way.
If you want to pick just one apple from a tree, which of the following
two sequences of instructions will work?
go to tree
pick apple
commit suicide
or
go to tree
commit suicide
pick apple
In the second case the apple does not get picked (I discount action hero
movies where the hero manages to appear dead, but then struggles up and
presses the button to save the world and only then dies).
If you use '-quit' before the '-exec' then you will not run the exec even
once. You need to swap the order.