Search This Blog

Saturday, May 05, 2012

pss: The Command-line Search Tool I Never Leave Home Without


Ever since I discovered the Python tool pss, I fell in love. It's blazingly fast and drop-dead simple to use. 99% of the time, you just type:
pss "search phrase"
The idea is pss REGEXP: you can use an escape character if you need to search for a character literal:
pss "\$method = 'post'"
or triple escape if searching for a single pattern (that is, an unquoted string):
pss \\\$method
I tend to think of pss as a sort of "grep+" for this kind of searching:* it's automatically recursive, whereas grep is not, and it ignores certain file types by default. (These can all be configured: for additional information, see Announcing pss, pss0.3.5, and Usage samples.)


Assuming that you have Python installed on your machine (if not, grab it here), you can install pss using pip:
pip install pss
If you do not have pip, you should be able to just type:
easy_install pip
pip install pss
Finally, if you don't have easy_install either, you can get the toolkit / directions at setuptools 0.6c11.

* grep is still invaluable for piped searches:

tail package.json | grep "MIT +no-false-attribs" 
yum list available | grep mysql

And don't forget find...

1. When you want to search for file / directory names:
# find the php.ini config file starting at the /etc directory
find /etc -name 'php.ini'
# find all .php files starting at local directory (.)
find . -name '*.php'
2. When you want to bulk-replace file extensions:
# change .JPG to .jpg for all files starting at local directory
find . -name '*.JPG' -exec rename -s .JPG .jpg {} \;
3. When you want to bulk delete files:
# delete all .pyc files starting at local directory
# GNU find
find . -name '*.pyc' -delete
# Universal
find . -name '*.pyc' | xargs rm -f {} \;

1 comment:


    Get professional trading signals delivered to your mobile phone every day.

    Start following our signals NOW & profit up to 270% per day.