Tag Archive: linux


Picked up a couple of handy command line tricks at work this week, and frankly I wish I had done so much earlier. I thought, what better way to commit them to permanent memory than to post it here, so here they are.

Subversion diff ignoring whitespace

svn diff --diff-cmd /usr/bin/diff -x -bBw -r9999 > r9999.diff

Compares the local copy with a particular revision; and uses the local diff command instead of the one built into the Subversion client.

The `-x` flags that the following option (in this case `-bBw`) is for the local diff command, instead of the Subversion command.

Find files containing a particular string recursively in a directory

find . -name \*.java -exec grep -n "searchstringregex" {} /dev/null \;

Lists all files within the current directory (recursively) which match a file glob pattern, and contain at least one line that matches a regular expression. Special characters in the file glob need to be escaped (e.g. `\*.java`), and the regex should be quoted.

The purpose of including `/dev/null` is to give the `grep` command more than one input file (per iteration), to force grep to output not just the matching string, but also the file name. This would be redundant if we are lookign at just one file, however it is quite useful, and necessary, here since we are grep’ping many files at once.

find . -name \*.java -exec grep -c "searchstringregex" {} /dev/null \; | grep -v :0$

A very slight variation on the previous command, this time with the number of occurrences of the regex in each file (`-c`) instead of the contents of each matching line. The output is filtered by piping it through another `grep` to remove items with a count of zero.

Advertisements

Python iView on Ubuntu

This is the Ubuntu counterpart to my earlier post about deploying python iView on Windows (python iView homepage).

Fortunately, it is much easier than Windows, everything is achieved with a single shell script.

#!/bin/bash
# Installs python-iview including all dependencies
# Script assumes /usr/bin in on the path (is with default installs)
# Brendan Graetz 20100521
#
# python-iview by Jeremy Visser: http://jeremy.visser.name/2009/08/30/python-iview/

#install bazaar and python library
sudo apt-get install bzr
sudo apt-get install python-beautifulsoup

#install dev dependencies in order to be able to compile
sudo apt-get install libssl-dev
sudo apt-get install zlib1g-dev

#download rtmpdump source
wget http://rtmpdump.mplayerhq.hu/download/rtmpdump-2.2d.tgz ~/Downloads/rtmpdump-2.2d.tgz

#compile rtmpdump & create softlink on path
cd /usr/local/
tar -xzf ~/Downloads/rtmpdump-2.2d.tgz
cd rtmpdump-2.2d
make posix
sudo ln -s `pwd`/rtmpdump /usr/bin/rtmpdump

#check out python iview from repository
cd /usr/local/
bzr branch http://jeremy.visser.name/bzr/python-iview/ ./python-iview

#create softlinks on path
sudo ln -s `pwd`/python-iview/iview-gtk /usr/bin/iview-gtk
sudo ln -s `pwd`/python-iview/iview-cli /usr/bin/iview-cli
sudo ln -s /usr/bin/iview-gtk /usr/bin/iview

The only somewhat tricky bit here is that you need to compile rtmpdump, because it does not distribute binaries (not .deb‘s anyway). For that you will need to install a couple of dependencies which are not immediately obvious: libssl-dev and zlib1g-dev.