Bash find and run script on files found

Find files using the find command and pass results to a script.

$ find $(pwd) -type f -name "*.csv" -exec php ~/process_file.php {} \;

Note: Use `find $(pwd)' instead of current directory `find .' so that the full path of each file found is passed to the script.

<?php
// process_file.php
$filename = $argv['1'];
echo 'filename: ' . $filename . "\n";
$ find $(pwd) -type f -name "*.csv" -exec php ~/process_file.php {} \;
filename: /tmp/test/1.csv
filename: /tmp/test/3.csv
filename: /tmp/test/2.csv
If you liked this posting, please feel free to leave me a comment below.
View this page on GitHub.
Posted .

Comments

Leave a Reply