bug-findutils
[Top][All Lists]
Advanced

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

Re: Passing directories and files


From: goncholden
Subject: Re: Passing directories and files
Date: Wed, 25 May 2022 17:53:47 +0000

Customarily people use  the -name option for specific file names.



Sent with Proton Mail secure email.
------- Original Message -------
On Thursday, May 26th, 2022 at 5:50 AM, goncholden <goncholden@protonmail.com> 
wrote:


> Was it designed to function with filenames then?
>
>
>
>
> Sent with Proton Mail secure email.
> ------- Original Message -------
> On Thursday, May 26th, 2022 at 5:35 AM, Bernhard Voelker 
> mail@bernhard-voelker.de wrote:
>
>
>
> > On 5/25/22 14:08, goncholden via Bug reports for the GNU find utilities 
> > wrote:
> >
> > > I am using the FIND command on a number of directories stored in FDIR 
> > > array to execute HEAD on each file. How can I adapt the code so users can 
> > > also include files as well as directories?
> >
> > well, I don't think there's anything to adjust, because `find` already
> > accepts both files and directories as starting points.
> >
> > > hn=8
> > > nf=${#fdir[@]}
> > > for (( i=0 ; i < $nf ; i++ )); do
> > > find "${fdir[$i]}" -type f \
> > > -exec head -v -n "$hn" '{}' +
> > > done
> > > The synopsis of the GNU find command is
> > >
> > > find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point...] 
> > > [expression]
> > >
> > > where [starting-point...] is zero or more paths. There is nothing 
> > > stopping the user from passing files as starting points
> >
> > no problem, find will just work well both with regular files or directories.
> > For the latter, it will descend the directory hierarchy, obviously.
> >
> > > Example, given:
> > >
> > > $ cat subdir/somefile
> > > foo
> > > bar
> > > baz
> > >
> > > then
> >
> > the following came out a bit mangled via email.
> >
> > > $ find subdir/somefile -
> > >
> > > type
> > >
> > > f -
> > >
> > > exec
> > >
> > > head -n 2 {} +
> > > foo
> > > bar
> > >
> > > I could just do
> > >
> > > find
> > >
> > > "
> > >
> > > ${fdir[@]}
> > >
> > > "
> > >
> > > -
> > >
> > > type
> > >
> > > f -
> > >
> > > exec
> > >
> > > head -v -n
> > >
> > > "
> > >
> > > $hn
> > >
> > > "
> > >
> > > '{}'
> > >
> > > +
> > >
> > > regardless of the mix of directories and files in FDIR.
> > >
> > > But is this the right and proper way to use the FIND command?
> >
> > Sure, why not? ;-)
> >
> > $ find subdir/somefile -type f -exec head -v -n1 '{}' +
> > ==> subdir/somefile <==
> >
> > foo
> >
> > $ find subdir -type f -exec head -v -n2 '{}' +
> > ==> subdir/somefile <==
> >
> > foo
> >
> > Have a nice day,
> > Berny



reply via email to

[Prev in Thread] Current Thread [Next in Thread]