bugfindutils - Bugs: bug #31338, find -exec bash -c mv only acts on...

 
 

bug #31338: find -exec bash -c mv only acts on first thing found by find

Submitted by:  Robin Anderson <rasyn>
Submitted on:  Fri 15 Oct 2010 03:54:29 AM UTC  
 
Category:  find Severity:  3 - Normal
Item Group:  None Status:  Works For Me
Privacy:  Public Assigned to:  James Youngman <jay>
Originator Name:  Open/Closed:  Closed
Release:  4.4.2 Fixed Release:  None

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Wed 11 May 2011 09:43:52 AM UTC, comment #5: 

No update since October 2010.   Closing due to lack of response.   Please reopen if you can provide the requested information.

James Youngman <jay>
Project AdministratorIn charge of this item.
Sat 02 Apr 2011 10:07:57 PM UTC, comment #4: 

For this bug to be progressed, we really need a specific answer to the earlier question "Could you define more closely what semantics exactly you are expecting?".

James Youngman <jay>
Project AdministratorIn charge of this item.
Sat 16 Oct 2010 09:29:24 AM UTC, comment #3: 

I'm leaving just the shell commands, to avoid markup issues.
echo "With echo find outputs for all three a.file, b.file, and c.file"
'echo cp "$1" ~/test/find/2/ && echo mv "${1%/*}" ~/test/find/3/'

Clearly the above command does not modify the filesystem.

echo "But when echo is removed, find only works on the first."
'set -x; cp "$1" ~/test/find/2/ && mv "${1%/*}" ~/test/find/3/'

This one modifies the filesystem while find is examining it:
+ cp /home/james/test/find/1/c/c.file /home/james/test/find/2/
+ mv /home/james/test/find/1/c /home/james/test/find/3/

/home/james/test/find/1/c is being moved somewhere else while (probably) find is inside it.    Since this time you are modifying the filesystem, while in the previous example you are not, I don't understand why you expect the output of find to be the same.

echo "Changing mv to cp -r then does more than one"
'set -x; cp "$1" ~/test/find/2/ && cp -r "${1%/*}" ~/test/find/3/'

Here you are adding new entries but nor removing or moving any, so it is not surprising that the output is longer.   But the initial conditions here are not the same as in your first example, because the second example has moved things around.   Fixing that produces a full set of output just like the first example.

I attach an example script with the change I mention.

(file #21691)

James Youngman <jay>
Project AdministratorIn charge of this item.
Sat 16 Oct 2010 03:18:08 AM UTC, comment #2: 

Thanks for looking into this. I expect to happen what is output with echo.

I expect that what echo outputs should run. Since the files and folders are still there, it should all work. Find seems to be stopping for no reason.

(file #21688)

Robin Anderson <rasyn>
Fri 15 Oct 2010 09:53:25 PM UTC, comment #1: 

Your example seems a bit unclear.  It's not too clear which command each part of the commentary refers to.

However, more generally, you are modifying the directory tree that find is searching, while it is searching it.   Could you define more closely what semantics exactly you are expecting?

A simpler example would help, too.   The best way to provide an example is to make it an attachment, since otherwise characters like * are interpreted as being markup.

James Youngman <jay>
Project AdministratorIn charge of this item.
Fri 15 Oct 2010 03:54:29 AM UTC, original submission:  

Pretty sure this is an issue with find. Works with echo, when they're removed it does not. mv doesn't work but cp -r does. Might be because find is looking in a nonexistent dir then thinks its done for some reason. Please edit any inaccurate parts of this bug submission.

If this is expected behavior, maybe find should output something about it stopping early.

Confirmed on Ubuntu 9.10 and on Arch both with findutils 4.4.2

Here's a small bash script to demonstrate the issue:

abe@ubuntu:~$ cat findtest.sh
#!/bin/bash
mkdir -p ~/test/find/{1,2,3}
mkdir ~/test/find/1/{a,b,c}
touch ~/test/find/1/a/a.file ~/test/find/1/b/b.file ~/test/find/1/c/c.file
find ~/test/find/1 -iname "*.file" -exec bash -c 'set -x; echo cp "$1" ~/test/find/2/ && echo mv "${1%/*}" ~/test/find/3/' -- {} \;
echo "for some reason this fails (only moves the first)"
find ~/test/find/1 -iname "*.file" -exec bash -c 'set -x; cp "$1" ~/test/find/2/ && mv "${1%/*}" ~/test/find/3/' -- {} \;
echo "but this works (does more than one, ie the last two)"
find ~/test/find/1 -iname "*.file" -exec bash -c 'set -x; cp "$1" ~/test/find/2/ && cp -r "${1%/*}" ~/test/find/3/' -- {} \;
echo "cleanup"
rm -r ~/test/find
abe@ubuntu:~$ bash findtest.sh
+ echo cp /home/abe/test/find/1/a/a.file /home/abe/test/find/2/
cp /home/abe/test/find/1/a/a.file /home/abe/test/find/2/
+ echo mv /home/abe/test/find/1/a /home/abe/test/find/3/
mv /home/abe/test/find/1/a /home/abe/test/find/3/
+ echo cp /home/abe/test/find/1/b/b.file /home/abe/test/find/2/
cp /home/abe/test/find/1/b/b.file /home/abe/test/find/2/
+ echo mv /home/abe/test/find/1/b /home/abe/test/find/3/
mv /home/abe/test/find/1/b /home/abe/test/find/3/
+ echo cp /home/abe/test/find/1/c/c.file /home/abe/test/find/2/
cp /home/abe/test/find/1/c/c.file /home/abe/test/find/2/
+ echo mv /home/abe/test/find/1/c /home/abe/test/find/3/
mv /home/abe/test/find/1/c /home/abe/test/find/3/
for some reason this fails (only moves the first)
+ cp /home/abe/test/find/1/a/a.file /home/abe/test/find/2/
+ mv /home/abe/test/find/1/a /home/abe/test/find/3/
but this works (does more than one, ie the last two)
+ cp /home/abe/test/find/1/b/b.file /home/abe/test/find/2/
+ cp -r /home/abe/test/find/1/b /home/abe/test/find/3/
+ cp /home/abe/test/find/1/c/c.file /home/abe/test/find/2/
+ cp -r /home/abe/test/find/1/c /home/abe/test/find/3/
cleanup

Robin Anderson <rasyn>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #21691:  findtest-consistent-start.sh added by jay (879B - application/x-shellscript)
file #21688:  findtest.sh added by rasyn (759B - application/x-shellscript)

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

     

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2011-05-11 jay StatusNeed Info => Works For Me
        Open/ClosedOpen => Closed
    2011-04-02 jay StatusNone => Need Info
    2010-10-16 jay Attached File- => Added findtest-consistent-start.sh, #21691
    2010-10-16 rasyn Attached File- => Added findtest.sh, #21688
    2010-10-15 jay Assigned toNone => jay

    Back to the top


    Powered by Savane 3.5