Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use <code>-exec</code> and <code>{}</code> features of the <code>find</code> command so you don't need any pipes at all:</p> <pre><code>find -maxdepth 1 -type d -name "*.y" -mtime +`expr 2 \* 365` -exec mv "{}" "{}.old" \; </code></pre> <p>Also you don't need to specify '.' path - this is default for <code>find</code>. And you used extra slashes in <code>"*.y"</code>. Of course if your file names do not really contain quotes.</p> <p>In fairness it should be noted, that version with <code>while read</code> loop is the fastest of proposed here. Here are some example measurements:</p> <pre><code>$ cat measure #!/bin/sh case $2 in 1) find "$1" -print0 | xargs -0 -I file echo mv file file.old ;; 2) find "$1" -exec echo mv '{}' '{}.old' \; ;; 3) find "$1" | while read file; do echo mv "$file" "$file.old" done;; esac $ time ./measure android-ndk-r5c 1 | wc 6225 18675 955493 real 0m6.585s user 0m18.933s sys 0m4.476s $ time ./measure android-ndk-r5c 2 | wc 6225 18675 955493 real 0m6.877s user 0m18.517s sys 0m4.788s $ time ./measure android-ndk-r5c 3 | wc 6225 18675 955493 real 0m0.262s user 0m0.088s sys 0m0.236s </code></pre> <p>I think it's because <code>find</code> and <code>xargs</code> invokes additional /bin/sh (actually <code>exec(3)</code> does it) every time for execute a command, while shell <code>while</code> loop do not.</p> <p><strong>Upd:</strong> If your busybox version was compiled without <code>-exec</code> option support for the <code>find</code> command then the <code>while</code> loop or <code>xargs</code>, suggested in the other answers (<a href="https://stackoverflow.com/a/8759463/566344">one</a>, <a href="https://stackoverflow.com/a/8759430/566344">two</a>), is your way.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload