bugfindutils - Bugs: bug #52409, `find -print0 -name ...` ignores...

 
 

bug #52409: `find -print0 -name ...` ignores `-name ...`

Submitter:  None
Submitted:  Tue 14 Nov 2017 11:46:44 PM UTC
   
 
Category:  find Severity:  3 - Normal
Item Group:  Wrong result Status:  Working as Intended
Privacy:  Public Assigned to:  None
Originator Name:  Anthony Sottile Originator Email:  -email is unavailable-
Open/Closed:  Closed Release:  4.6.0
Fixed Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 15 Nov 2017 03:29:31 AM UTC, comment #2: 

Ah makes sense!  Thanks for the thorough explanation -- didn't realize `print` was considered a predicate and thought it just controlled the final output.

This can be closed -- apparently I can't do that since I posted anonymously.

Anonymous
Wed 15 Nov 2017 02:23:50 AM UTC, comment #1: 

Actually, this is a usage error:  -print is an action as well as a predicate.  In particular, it takes effect when it is executed in order among the predicates.  So if you execute

find . -name '*.c' -print

find will, for each file name, first test to see if it passes the -name test, and then if it does, test to see if it passes the -print test.  -print always succeeds, but as a side-effect, it prints the name.  And consecutive predicates are implicitly connected by "and", or rather, the short-circuiting "&&" operator of C.

If you execute

find . -name '*.c' -print -print

it will print every .c name *twice, as there are two -print predicates to execute.

If you execute

find . -name '*.c'

it will print every *.c name once, because find appends -print to command lines that have no side-effect-causing predicates.

If you execute

find . -print -name '*.c"

find will, for each name, first print it and then test if it matches *.c.

Dale Worley <worley>
Tue 14 Nov 2017 11:46:44 PM UTC, original submission:  

The version I'm using ships with ubuntu xenial, but I also downloaded 4.6.0 and reproduced there:

```
$ find --version
find (GNU findutils) 4.7.0-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS(FTS_CWDFD) CBO(level=2)

$ ./find/find --version
find (GNU findutils) 4.6.0
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS(FTS_CWDFD) CBO(level=2)
```

Here's a toy testcase:

```
mkdir foo && cd foo
touch foo.{a,b,c}
# works, prints only `foo.c`
find -name '*.c'
# works, prints only `foo.c`
find -name '*.c' -print0 | xargs -0 -n1
# BUG: prints . foo.a foo.b and foo.c
find -print0 -name '*.c' | xargs -0 -n1
```

Output:

```
$ mkdir foo && cd foo
$ touch foo.{a,b,c}
$ # works, prints only `foo.c`
$ find -name '*.c'
./foo.c
$ # works, prints only `foo.c`
$ find -name '*.c' -print0 | xargs -0 -n1
./foo.c
$ # BUG: prints . foo.a foo.b and foo.c
$ find -print0 -name '*.c' | xargs -0 -n1
.
./foo.a
./foo.b
./foo.c
```

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jay (Updated the item)
  • -email is unavailable- added by worley (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-11-15 jay StatusNone Working as Intended
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code