Executing a command line in a directory and its subdirectories

I'm finally about to make the jump from PHP's mysql driver to the newer mysqli one using the mysqli converter tool.

The tool is called by this command line:

php /usr/share/nginx/html/rather/converter/cli.php -d [a dir] -p ".php,.shtml,.inc" -u -b -v -w  >> /tmp/convert.log

e.g. at the web root:

php /usr/share/nginx/html/rather/converter/cli.php -d /usr/share/nginx/html -p ".php,.shtml,.inc" -u -b -v -w >> /tmp/convert.log

It's a fast tool and I'm trying to minimize downtime and errors I might make by missing a subdir level.

How would I get a list, starting at /usr/share/nginx/html and drilling down, then feed it to that command line?

Thanks for any pointers.

I suggest to consult the man page for find . Switches you probably will find useful include:

  • -type limits the resulting list to file system items of the specified type: -type -f finds only files, -type -d only directories, etc.
  • -name only items matching the given name pattern are found. -name "*php" will find only php-files.
  • -exec allows to execute an arbitrary command on every item found.

You might find this little introduction to find useful.

I hope this helps.

bakunin

1 Like

-execdir may also be of interest.

Regards,
Alister