Can a filename pattern specify both hidden and non-hidden files

Can a filename pattern specify both hidden and non-hidden files

am 21.01.2007 07:23:31 von lovecreatesbeauty

I use find command in the following script to count files with
specified filename patterns of suffixes only in current directory
excluding its sub-directories.

But with * (star) in the -name pattern, I can't count hidden files
whose names begin with . (dot). If I use .* instead of *, then I only
count the hidden files. How can I count both hidden and non-hidden
files? Thank you.

#tested on Linux 2.4.27-2-386
#!/bin/sh

threshold=100
p='/home/jhl';
d='/*';
c='*'

find "$p" -path "$p$d" -prune -name "$c" -type f |
awk 'END {print NR}' |
if read cnt; then
if [ $cnt -le $threshold ]; then
echo -e "[INFO] directory: "$p", files: "$c", count: "$cnt",
\c"
echo "within limitation: "$threshold""
fi
fi

Re: Can a filename pattern specify both hidden and non-hidden files

am 21.01.2007 07:43:29 von Icarus Sparry

On Sat, 20 Jan 2007 22:23:31 -0800, lovecreatesbea...@gmail.com wrote:

> I use find command in the following script to count files with
> specified filename patterns of suffixes only in current directory
> excluding its sub-directories.
>
> But with * (star) in the -name pattern, I can't count hidden files
> whose names begin with . (dot). If I use .* instead of *, then I only
> count the hidden files. How can I count both hidden and non-hidden
> files? Thank you.
>
> #tested on Linux 2.4.27-2-386
> #!/bin/sh
>
> threshold=100
> p='/home/jhl';
> d='/*';
> c='*'
>
> find "$p" -path "$p$d" -prune -name "$c" -type f |
> awk 'END {print NR}' |
> if read cnt; then
> if [ $cnt -le $threshold ]; then
> echo -e "[INFO] directory: "$p", files: "$c", count: "$cnt",
> \c"
> echo "within limitation: "$threshold""
> fi
> fi

The most obvious way to answer your question is to use

\( -name "*" -o -name ".*" \)

instead of
-name "*"
Obviously in the special case where you want to match everything, then
don't specify any restrictions on names in the first place.

Re: Can a filename pattern specify both hidden and non-hidden files

am 21.01.2007 15:31:14 von Ed Morton

lovecreatesbea...@gmail.com wrote:
> I use find command in the following script to count files with
> specified filename patterns of suffixes only in current directory
> excluding its sub-directories.
>
> But with * (star) in the -name pattern, I can't count hidden files
> whose names begin with . (dot). If I use .* instead of *, then I only
> count the hidden files. How can I count both hidden and non-hidden
> files?

*.*

Ed.

Re: Can a filename pattern specify both hidden and non-hidden files

am 21.01.2007 16:01:06 von lovecreatesbeauty

Icarus Sparry wrote:
> On Sat, 20 Jan 2007 22:23:31 -0800, lovecreatesbea...@gmail.com wrote:
>
> > I use find command in the following script to count files with
> > specified filename patterns of suffixes only in current directory
> > excluding its sub-directories.
> >
> > But with * (star) in the -name pattern, I can't count hidden files
> > whose names begin with . (dot). If I use .* instead of *, then I only
> > count the hidden files. How can I count both hidden and non-hidden
> > files? Thank you.
> >
> > #tested on Linux 2.4.27-2-386
> > #!/bin/sh
> >
> > threshold=100
> > p='/home/jhl';
> > d='/*';
> > c='*'
> >
> > find "$p" -path "$p$d" -prune -name "$c" -type f |
> > awk 'END {print NR}' |
> > if read cnt; then
> > if [ $cnt -le $threshold ]; then
> > echo -e "[INFO] directory: "$p", files: "$c", count: "$cnt",
> > \c"
> > echo "within limitation: "$threshold""
> > fi
> > fi
>
> The most obvious way to answer your question is to use
>
> \( -name "*" -o -name ".*" \)
>
> instead of
> -name "*"
> Obviously in the special case where you want to match everything, then
> don't specify any restrictions on names in the first place.

Thank you.

It works. The two conditions can be combined using -o operator. I
wasn't aware of that before.

Re: Can a filename pattern specify both hidden and non-hidden files

am 21.01.2007 18:01:03 von Janis Papanagnou

Ed Morton wrote:
> lovecreatesbea...@gmail.com wrote:
>
>> I use find command in the following script to count files with
>> specified filename patterns of suffixes only in current directory
>> excluding its sub-directories.
>>
>> But with * (star) in the -name pattern, I can't count hidden files
>> whose names begin with . (dot). If I use .* instead of *, then I only
>> count the hidden files. How can I count both hidden and non-hidden
>> files?

> *.*

*.* will match only files with dots in their name.
Was there a space intended between * [non-hidden] and .* [hidden]?

Janis

Re: Can a filename pattern specify both hidden and non-hidden files

am 21.01.2007 18:33:00 von Ed Morton

Janis Papanagnou wrote:
> Ed Morton wrote:
>
>> lovecreatesbea...@gmail.com wrote:
>>
>>> I use find command in the following script to count files with
>>> specified filename patterns of suffixes only in current directory
>>> excluding its sub-directories.
>>>
>>> But with * (star) in the -name pattern, I can't count hidden files
>>> whose names begin with . (dot). If I use .* instead of *, then I only
>>> count the hidden files. How can I count both hidden and non-hidden
>>> files?
>
>
>> *.*
>
>
> *.* will match only files with dots in their name.
> Was there a space intended between * [non-hidden] and .* [hidden]?

No, I just needed more coffee...

Thanks,

Ed.

Re: Can a filename pattern specify both hidden and non-hidden files

am 22.01.2007 12:08:17 von Stephane CHAZELAS

2007-01-20, 22:23(-08), lovecreatesbea...@gmail.com:
> I use find command in the following script to count files with
> specified filename patterns of suffixes only in current directory
> excluding its sub-directories.
>
> But with * (star) in the -name pattern, I can't count hidden files
> whose names begin with . (dot).
[...]

Then report it as a bug in your find implementation.

If using GNU find, upgrade to a later release. That was fixed in
version 4.2.2 in 2004.

-name '*'
should match dot files (except that "." and ".." are not
considered when find descend into directories).

--
Stéphane