Skip to main content
typos
Source Link
Stéphane Chazelas
  • 586.9k
  • 96
  • 1.1k
  • 1.7k

That's what the -exec predicate is for:

find /some/path -type f -name file.pl -size +10M -exec perl /my/script.pl {} \;

If you do want to run have your shellyour shell run the commands based on the output of find, then that will have to be bash/zsh specific if you want to be reliable as in:

  • zsh:

     IFS=$'\0'
     for f ($(find /some/path -type f -name file.pl -size +10M -print0)) {
       /my/script.pl $f
     }
    

though in zsh, you can simply do:

    for f (./**/file.pl(.LM+10)) /my/script.pl $f
  • bash/zsh

     while IFS= read -rd '' -u3 file; do
       /my/script.pl "$file"
     done 3< <(find /some/path -type f -name file.pl -size +10M -print0)
    

Whatever you do, in bash or other POSIX shells, avoid:

for file in $(find...)

Or at least make it less bad by fixing the field separator to newline and disable globbing:

IFS='
'; set -f; for file in $(find...)

(which will still fail for file paths that contain newline characters).

That's what the -exec predicate is for:

find /some/path -type f -name file.pl -size +10M -exec perl /my/script.pl {} \;

If you do want to run have your shell run the commands based on the output of find, then that will have to be bash/zsh specific if you want to be reliable as in:

  • zsh:

     IFS=$'\0'
     for f ($(find /some/path -type f -name file.pl -size +10M -print0)) {
       /my/script.pl $f
     }
    

though in zsh, you can simply do:

    for f (./**/file.pl(.LM+10)) /my/script.pl $f
  • bash/zsh

     while IFS= read -rd '' -u3 file; do
       /my/script.pl "$file"
     done 3< <(find /some/path -type f -name file.pl -size +10M -print0)
    

Whatever you do, in bash or other POSIX shells, avoid:

for file in $(find...)

Or at least make it less bad by fixing the field separator to newline and disable globbing:

IFS='
'; set -f; for file in $(find)

(which will still fail for file paths that contain newline characters).

That's what the -exec predicate is for:

find /some/path -type f -name file.pl -size +10M -exec perl /my/script.pl {} \;

If you do want to have your shell run the commands based on the output of find, then that will have to be bash/zsh specific if you want to be reliable as in:

  • zsh:

     IFS=$'\0'
     for f ($(find /some/path -type f -name file.pl -size +10M -print0)) {
       /my/script.pl $f
     }
    

though in zsh, you can simply do:

    for f (./**/file.pl(.LM+10)) /my/script.pl $f
  • bash/zsh

     while IFS= read -rd '' -u3 file; do
       /my/script.pl "$file"
     done 3< <(find /some/path -type f -name file.pl -size +10M -print0)
    

Whatever you do, in bash or other POSIX shells, avoid:

for file in $(find...)

Or at least make it less bad by fixing the field separator to newline and disable globbing:

IFS='
'; set -f; for file in $(find...)

(which will still fail for file paths that contain newline characters).

added 3 characters in body
Source Link
Stéphane Chazelas
  • 586.9k
  • 96
  • 1.1k
  • 1.7k

That's what the -exec predicate is for:

find /some/path -type f -name file.pl -size +10M -exec perl /my/script.pl {} \;

If you do want to run have your shell run the commands based on the output of find, then that will have to be bash/zsh specific if you want to be reliable as in:

  • zsh:

     IFS=$'\0'
     for f ($(find /some/path -type f -name file.pl -size +10M -print0)) {
       /my/script.pl $f
     }
    

though in zsh, you can simply do:

    for f (./**/file.pl(.LM+10)) /my/script.pl $f
  • bash/zsh

     while IFS= read -rd '' -u3 file; do
       /my/script.pl "$f""$file"
     done 3< <(find /some/path -type f -name file.pl -size +10M -print0)
    

Whatever you do, in bash or other POSIX shells, avoid:

for file in $(find...)

Or at least make it less bad by fixing the field separator to newline and disable globbing:

IFS='
'; set -f; for file in $(find)

(which will still fail for file paths that contain newline characters).

That's what the -exec predicate is for:

find /some/path -type f -name file.pl -size +10M -exec perl /my/script.pl {} \;

If you do want to run have your shell run the commands based on the output of find, then that will have to be bash/zsh specific if you want to be reliable as in:

  • zsh:

     IFS=$'\0'
     for f ($(find /some/path -type f -name file.pl -size +10M -print0)) {
       /my/script.pl $f
     }
    

though in zsh, you can simply do:

    for f (./**/file.pl(.LM+10)) /my/script.pl $f
  • bash/zsh

     while IFS= read -rd '' -u3 file; do
       /my/script.pl "$f"
     done 3< <(find /some/path -type f -name file.pl -size +10M -print0)
    

Whatever you do, in bash or other POSIX shells, avoid:

for file in $(find...)

Or at least make it less bad by fixing the field separator to newline and disable globbing:

IFS='
'; set -f; for file in $(find)

(which will still fail for file paths that contain newline characters).

That's what the -exec predicate is for:

find /some/path -type f -name file.pl -size +10M -exec perl /my/script.pl {} \;

If you do want to run have your shell run the commands based on the output of find, then that will have to be bash/zsh specific if you want to be reliable as in:

  • zsh:

     IFS=$'\0'
     for f ($(find /some/path -type f -name file.pl -size +10M -print0)) {
       /my/script.pl $f
     }
    

though in zsh, you can simply do:

    for f (./**/file.pl(.LM+10)) /my/script.pl $f
  • bash/zsh

     while IFS= read -rd '' -u3 file; do
       /my/script.pl "$file"
     done 3< <(find /some/path -type f -name file.pl -size +10M -print0)
    

Whatever you do, in bash or other POSIX shells, avoid:

for file in $(find...)

Or at least make it less bad by fixing the field separator to newline and disable globbing:

IFS='
'; set -f; for file in $(find)

(which will still fail for file paths that contain newline characters).

Rollback to Revision 2
Source Link
Stéphane Chazelas
  • 586.9k
  • 96
  • 1.1k
  • 1.7k

That's what the -exec predicate is for:

find /some/path -type f -name file.pl -size +10M -exec perl /my/script.pl "{}" \;

If you do want to run have your shell run the commands based on the output of find, then that will have to be bash/zsh specific if you want to be reliable as in:

  • zsh:

     IFS=$'\0'
     for f ($(find /some/path -type f -name file.pl -size +10M -print0)) {
       /my/script.pl $f
     }
    

though in zsh, you can simply do:

    for f (./**/file.pl(.LM+10)) /my/script.pl $f
  • bash/zsh

     while IFS= read -rd '' -u3 file; do
       /my/script.pl "$f"
     done 3< <(find /some/path -type f -name file.pl -size +10M -print0)
    

Whatever you do, in bash or other POSIX shells, avoid:

for file in $(find...)

Or at least make it less bad by fixing the field separator to newline and disable globbing:

IFS='
'; set -f; for file in $(find)

(which will still fail for file paths that contain newline characters).

That's what the -exec predicate is for:

find /some/path -type f -name file.pl -size +10M -exec perl /my/script.pl "{}" \;

If you do want to run have your shell run the commands based on the output of find, then that will have to be bash/zsh specific if you want to be reliable as in:

  • zsh:

     IFS=$'\0'
     for f ($(find /some/path -type f -name file.pl -size +10M -print0)) {
       /my/script.pl $f
     }
    

though in zsh, you can simply do:

    for f (./**/file.pl(.LM+10)) /my/script.pl $f
  • bash/zsh

     while IFS= read -rd '' -u3 file; do
       /my/script.pl "$f"
     done 3< <(find /some/path -type f -name file.pl -size +10M -print0)
    

Whatever you do, in bash or other POSIX shells, avoid:

for file in $(find...)

Or at least make it less bad by fixing the field separator to newline and disable globbing:

IFS='
'; set -f; for file in $(find)

(which will still fail for file paths that contain newline characters).

That's what the -exec predicate is for:

find /some/path -type f -name file.pl -size +10M -exec perl /my/script.pl {} \;

If you do want to run have your shell run the commands based on the output of find, then that will have to be bash/zsh specific if you want to be reliable as in:

  • zsh:

     IFS=$'\0'
     for f ($(find /some/path -type f -name file.pl -size +10M -print0)) {
       /my/script.pl $f
     }
    

though in zsh, you can simply do:

    for f (./**/file.pl(.LM+10)) /my/script.pl $f
  • bash/zsh

     while IFS= read -rd '' -u3 file; do
       /my/script.pl "$f"
     done 3< <(find /some/path -type f -name file.pl -size +10M -print0)
    

Whatever you do, in bash or other POSIX shells, avoid:

for file in $(find...)

Or at least make it less bad by fixing the field separator to newline and disable globbing:

IFS='
'; set -f; for file in $(find)

(which will still fail for file paths that contain newline characters).

added 2 characters in body
Source Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420
Loading
added 902 characters in body
Source Link
Stéphane Chazelas
  • 586.9k
  • 96
  • 1.1k
  • 1.7k
Loading
Source Link
Stéphane Chazelas
  • 586.9k
  • 96
  • 1.1k
  • 1.7k
Loading