Grep/Find Tools for locating text in Linux.
on
1) Problem with stripping front & back slashes
Looking for an easy way to find php array definitions without quotes
$foo[bar] = 'bad';
with definitions with quotes:
$foo['bar'] = 'good';
Peter Bojanic suggested the following:
grep \"[[^'\"$].*[^'\"]]\" *.php
Which is the set of all things in square brackets that do not start with either quote character or a $. This set includes some valid extras, like $bits[count($bits)-1], but you just have to careful.
Extra spaces below a ?> in a php script can cause problems with cookies, caching, sessions, etc.. It's often a problem finding which file has the extra spaces. However the following find commands (written by Peter Bojanic & David O'Neill):
find . -name *.php -o -name *.class -o -name *.inc | xargs -n 1 perl -0777ne 'print $ARGV,\"n\" if !(/?>$s) && !(?>[r]$s)'
If you're not worried about trailing white space, then the following version can narrow the results down a bit bit more:
find . -name *.php -o -name *.class -o -name *.inc | xargs -n 1 perl -0777ne 'print $ARGV,\"n\" if !(?>[ t]*$s) && !(?>[ t]*[r]$/s)' 2) Finding recently mofidifed files This is a useful way to find recently modified files: find /file/path/ -mtime -30 -type f
Share this article
About The Author
Mike Gifford is the founder of OpenConcept Consulting Inc, which he started in 1999. Since then, he has been particularly active in developing and extending open source content management systems to allow people to get closer to their content. Before starting OpenConcept, Mike had worked for a number of national NGOs including Oxfam Canada and Friends of the Earth.