[Top][All Lists]

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

execdir plus and commands generated

From: Peggy Russell
Subject: execdir plus and commands generated
Date: Mon, 28 Mar 2011 22:56:44 -0500
User-agent: KMail/1.12.4 (Linux/; KDE/4.3.5; x86_64; ; )


Why does `find` process file 'abc4' separately from files 'abc1-3', 
when they are in the same directory. This creates  3 `rm` commands
instead of 2 (assuming it looks like a `rm` for all files per 
directory)? Files 'abc1-4' are in the current directory. File 'def1' 
is in a sub directory.  Is there a way to get `execdir +` to produce 
1 `rm` like `xargs` (see below)?

Here's the Test Data:
  mkdir -p test/bar
  touch test/abc{1,2,3,4}.txt test/bar/def1.txt test/"s p a c e.txt"
  cd test
  run find command

  find . -name "*" -printf '[%y] %-20p%i\n'
  [d] .                   60104719
  [f] ./abc4.txt          60104730     <--- 1st rm
  [d] ./bar               60104720     
  [f] ./bar/def1.txt      60104731     <--- 2nd rm
  [f] ./abc3.txt          60104728     <--- 3rd rm
  [f] ./s p a c e.txt     60104732          |
  [f] ./abc2.txt          60104722          | 
  [f] ./abc1.txt          60104721          | 

Here's the Find Command:

  find . -type f -name "*.txt" \
    -execdir bash -c 'echo "+++Deleting $@ - $(pwd)"; rm "$@"' dmy {} +

  +++Deleting ./abc4.txt - /project/test/test
  +++Deleting ./def1.txt - /project/test/test/bar
  +++Deleting ./abc3.txt ./s p a c e.txt ./abc2.txt ./abc1.txt 
     - /project/test/test

I often see it recommended to use xargs instead of exec/execdir, and
wonder if that still applies... 

The `xargs` below produced 1 `rm` command. It seems to be a complement 
with benefits to the above `-execdir +` which produced 3 `rm`.  

  time find . -type f -name "*.txt" -print0 |
    xargs -0  bash -c 'echo "+++Deleting $@ - $(pwd)"; rm "$@"' --

The `xargs` (-I{} implies -L1) and `execdir \;`  below each produced 
6 `rm` commands each.

  find . -type f -name "*.txt" \
    -execdir bash -c 'echo "+++Deleting {} - $(pwd)"; rm "{}"' \;

  find . -type f -name "*.txt" -print0 |
    xargs -0I {} bash -c 'echo "+++Deleting {} - $(pwd)"; rm "{}"'

Thank you.
Peggy Russell

reply via email to

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