Useful Linux Commands 08/2008

Inspired by the book “The Productive Programmer” I was paying attention more and more on how I actually get things done and how I could better exploit existing shortcuts or faster paths.

Please do not ask why, but I had the following problem: One my PHP-Apps had scattered syntax errors. The question was, how I could locate them in the application. The first attempt was to let Zend Studio analyse the project… This was very slow and contained a lot of information which I actually did not want to see.

So I came up with the following solution:

find -name ‘*.php’ | xargs -i php -l {} | grep ‘Parser error:’

There are 3 parts piped together:

  1. find: Lists all .php files in your project.
  2. xargs: Executes one command for each of the lines coming from standard input. The -i flag replaces one line from STDIN with the {}. The php-executalbe has a flag -l (=lowercase L), which lets php check for correct syntax only.
  3. grep: Filters the output (lots of output like ‘No syntax errors detected in ./includes/’) to the actual information I liked to see: The files which had syntax errors.

From this experience I learned the following:

  • Pay attention to flags of commandline tools, even if they do not appear useful at first sight – like the ‘php -l script.php’. They might be very useful when combined via pipe with other commands.
  • I understood one more time the power of the commandline and will more often visit man pages of commands.

One thought on “Useful Linux Commands 08/2008

Comments are closed.