FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora User

 
 
LinkBack Thread Tools
 
Old 12-08-2007, 11:27 AM
"Razvan RACASANU"
 
Default find with -print0 returns incorrect results

Hi,

I'm having some problems using find with -print0: it is returning
different files depending on the position of -print0.

To illustrate this, suppose the current directory has 3 files: a.html,
a.css and a.js. From this directory I would like to list the file
names of all html and js files, but not those of css files.

If I try this:
find . -type f -print0 -iname "*.html" -or -iname "*.js" | xargs -0
the result looks like this:
./a.html ./a.js ./a.css

If I try this:
find . -print0 -type f -iname "*.html" -or -iname "*.js" | xargs -0
the result looks like this:
. ./a.html ./a.css

If I try this:
find . -type f -iname "*.html" -or -iname "*.js" -print0 | xargs -0
the result looks like this:
./a.js

Can anybody shed some light on what am I doing wrong?

Thanks,
Razvan RACASANU

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 12-08-2007, 12:57 PM
Luciano Rocha
 
Default find with -print0 returns incorrect results

On Sat, Dec 08, 2007 at 02:27:19PM +0200, Razvan RACASANU wrote:
> Hi,
>
> I'm having some problems using find with -print0: it is returning
> different files depending on the position of -print0.

Yes, position matters in find. Think of -print0 of just another test.

> To illustrate this, suppose the current directory has 3 files: a.html,
> a.css and a.js. From this directory I would like to list the file
> names of all html and js files, but not those of css files.
>
> If I try this:
> find . -type f -print0 -iname "*.html" -or -iname "*.js" | xargs -0
<snip>

What you want:
find . -type f ( -iname '*.html' -o -iname '*.js' ) -print0

--
lfr
0/0
--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 12-08-2007, 03:22 PM
Tony Nelson
 
Default find with -print0 returns incorrect results

At 2:27 PM +0200 12/8/07, Razvan RACASANU wrote:
>Hi,
>
>I'm having some problems using find with -print0: it is returning
>different files depending on the position of -print0.
>
>To illustrate this, suppose the current directory has 3 files: a.html,
>a.css and a.js. From this directory I would like to list the file
>names of all html and js files, but not those of css files.
>
>If I try this:
> find . -type f -print0 -iname "*.html" -or -iname "*.js" | xargs -0
>the result looks like this:
> ./a.html ./a.js ./a.css
>
>If I try this:
> find . -print0 -type f -iname "*.html" -or -iname "*.js" | xargs -0
>the result looks like this:
> . ./a.html ./a.css
>
>If I try this:
> find . -type f -iname "*.html" -or -iname "*.js" -print0 | xargs -0
>the result looks like this:
> ./a.js
>
>Can anybody shed some light on what am I doing wrong?

Conditions in find that aren't joined with an explicit operation are joined
with an implicit "and", so you effectively had '( -type f -and -iname
"*.html" ) -or -iname "*.js"', where the first -iname was bound to -type
by the implicit -and and operator precedence.
--
__________________________________________________ __________________
TonyN.:' <mailto:tonynelson@georgeanelson.com>
' <http://www.georgeanelson.com/>

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 12-08-2007, 06:50 PM
John Summerfield
 
Default find with -print0 returns incorrect results

Tony Nelson wrote:

At 2:27 PM +0200 12/8/07, Razvan RACASANU wrote:

Hi,

I'm having some problems using find with -print0: it is returning
different files depending on the position of -print0.

To illustrate this, suppose the current directory has 3 files: a.html,
a.css and a.js. From this directory I would like to list the file
names of all html and js files, but not those of css files.

If I try this:
find . -type f -print0 -iname "*.html" -or -iname "*.js" | xargs -0
the result looks like this:
./a.html ./a.js ./a.css

If I try this:
find . -print0 -type f -iname "*.html" -or -iname "*.js" | xargs -0
the result looks like this:
. ./a.html ./a.css

If I try this:
find . -type f -iname "*.html" -or -iname "*.js" -print0 | xargs -0
the result looks like this:
./a.js

Can anybody shed some light on what am I doing wrong?


Conditions in find that aren't joined with an explicit operation are joined
with an implicit "and", so you effectively had '( -type f -and -iname
"*.html" ) -or -iname "*.js"', where the first -iname was bound to -type
by the implicit -and and operator precedence.

Not quite. from 'man find'
-print True; print the full file name on the standard output,
followed by a newline.


-print0
True; print the full file name on the standard
output, followed by a null character. This allows
file names that contain newlines to be correctly
interpreted by programs that process the find out-

put.



--

Cheers
John

-- spambait
1aaaaaaa@coco.merseine.nu Z1aaaaaaa@coco.merseine.nu
-- Advice
http://webfoot.com/advice/email.top.php
http://www.catb.org/~esr/faqs/smart-questions.html
http://support.microsoft.com/kb/555375

You cannot reply off-list:-)

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 12-10-2007, 08:23 PM
"Razvan RACASANU"
 
Default find with -print0 returns incorrect results

Thanks for your answers, but I still have a question about this.

So, if I understand correctly, -print0 is considered as just another
test (just like -iname) that is evaluated for each file according to
operator precedence. In this case, since -print0 always returns true,
shouldn't the following commands be equivalent:

find . -type f -and -print0 -and ( -iname '*.html' -or -iname
'*.js' ) | xargs -0
and
find . -type f -and ( -iname '*.html' -or -iname '*.js' ) -and
-print0 | xargs -0

The first one outputs:
./a.js ./a.css ./a.html
The second one outputs:
./a.js ./a.html

Thanks,
Razvan RACASANU

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 12-10-2007, 08:31 PM
Luciano Rocha
 
Default find with -print0 returns incorrect results

On Mon, Dec 10, 2007 at 11:23:17PM +0200, Razvan RACASANU wrote:
> Thanks for your answers, but I still have a question about this.
>
> So, if I understand correctly, -print0 is considered as just another
> test (just like -iname) that is evaluated for each file according to
> operator precedence. In this case, since -print0 always returns true,
> shouldn't the following commands be equivalent:
>
> find . -type f -and -print0 -and ( -iname '*.html' -or -iname
> '*.js' ) | xargs -0
> and
> find . -type f -and ( -iname '*.html' -or -iname '*.js' ) -and
> -print0 | xargs -0
>

No, because tests are evaluated in order:

1. Is type f? yes. print0? yes (always yes). ...
2. Is type f? yes. ends with html or js? yes. print0? yes.

--
lfr
0/0
--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 12-10-2007, 08:52 PM
Rick Stevens
 
Default find with -print0 returns incorrect results

On Mon, 2007-12-10 at 23:23 +0200, Razvan RACASANU wrote:
> Thanks for your answers, but I still have a question about this.
>
> So, if I understand correctly, -print0 is considered as just another
> test (just like -iname) that is evaluated for each file according to
> operator precedence. In this case, since -print0 always returns true,
> shouldn't the following commands be equivalent:
>
> find . -type f -and -print0 -and ( -iname '*.html' -or -iname
> '*.js' ) | xargs -0
> and
> find . -type f -and ( -iname '*.html' -or -iname '*.js' ) -and
> -print0 | xargs -0
>
> The first one outputs:
> ./a.js ./a.css ./a.html
> The second one outputs:
> ./a.js ./a.html

No. Remember, -print0 prints immediately, so the only test that was
applied before the print was "-type f" in the first one. In the second
one, you did the "-iname" tests. Since they fail on the "a.css" file,
the -print0 wasn't invoked for that file.

----------------------------------------------------------------------
- Rick Stevens, Principal Engineer rstevens@internap.com -
- CDN Systems, Internap, Inc. http://www.internap.com -
- -
- Always remember you're unique, just like everyone else. -
----------------------------------------------------------------------

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 12-10-2007, 09:52 PM
John Summerfield
 
Default find with -print0 returns incorrect results

Razvan RACASANU wrote:

Thanks for your answers, but I still have a question about this.

So, if I understand correctly, -print0 is considered as just another
test (just like -iname) that is evaluated for each file according to
operator precedence. In this case, since -print0 always returns true,
shouldn't the following commands be equivalent:


Think about the order of evaluation.



find . -type f -and -print0 -and ( -iname '*.html' -or -iname
'*.js' ) | xargs -0
and
find . -type f -and ( -iname '*.html' -or -iname '*.js' ) -and
-print0 | xargs -0

The first one outputs:
./a.js ./a.css ./a.html
The second one outputs:
./a.js ./a.html


GNU find has an implied print at the end, iff there has been no other
print 'test." Not all versions of find does this.


In this context, by "print" I include any test that prints.

--

Cheers
John

-- spambait
1aaaaaaa@coco.merseine.nu Z1aaaaaaa@coco.merseine.nu
-- Advice
http://webfoot.com/advice/email.top.php
http://www.catb.org/~esr/faqs/smart-questions.html
http://support.microsoft.com/kb/555375

You cannot reply off-list:-)

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 12-11-2007, 07:02 AM
"Razvan RACASANU"
 
Default find with -print0 returns incorrect results

On Dec 10, 2007 11:52 PM, Rick Stevens <rstevens@internap.com> wrote:
>
> No. Remember, -print0 prints immediately, so the only test that was
> applied before the print was "-type f" in the first one. In the second
> one, you did the "-iname" tests. Since they fail on the "a.css" file,
> the -print0 wasn't invoked for that file.

Thanks a lot. As I originally understood it, -print0 was just another
test, so the evaluation order should not have mattered in that case,
but now it makes perfect sense.

Thanks,
Razvan RACASANU

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 12-11-2007, 06:47 PM
Rick Stevens
 
Default find with -print0 returns incorrect results

On Tue, 2007-12-11 at 10:02 +0200, Razvan RACASANU wrote:
> On Dec 10, 2007 11:52 PM, Rick Stevens <rstevens@internap.com> wrote:
> >
> > No. Remember, -print0 prints immediately, so the only test that was
> > applied before the print was "-type f" in the first one. In the second
> > one, you did the "-iname" tests. Since they fail on the "a.css" file,
> > the -print0 wasn't invoked for that file.
>
> Thanks a lot. As I originally understood it, -print0 was just another
> test, so the evaluation order should not have mattered in that case,
> but now it makes perfect sense.

Glad to hear it. BTW, the evaluation order is significant with an
optimized system. In a chain of "ands" such as "a and b and c", if a is
true and b is false, there's no reason to even evaluate c, since the
proposition is already false. Most systems take advantage of that to
speed execution. Yes, it technically violates Boole's laws, but what
the heck?

----------------------------------------------------------------------
- Rick Stevens, Principal Engineer rstevens@internap.com -
- CDN Systems, Internap, Inc. http://www.internap.com -
- -
- Tempt not the dragons of fate, since thou art crunchy and taste -
- good with ketchup. -
----------------------------------------------------------------------

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 

Thread Tools




All times are GMT. The time now is 06:44 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org