Philip Hutchins

Head in the cloud...

Handy Shortcuts

OSX

Ctrl + Shift + h – Visual list of history in iTerm2

Linux

Command Line

Iterate through all files in a directory and split the names to be used also as directory name

1
for file in *; do echo "Checking $file"; diff ./$file ~/github/backseat/widgets/$(echo ${file//.*/ })/$file; done

Perform a find and replace on multiple files at once using find and perl

1
find /path/to/directory -name "*.txt" | xargs perl -pi -e 's/stringtoreplace/replacementstring/g'

Kill multiple processes at the same time using ps and grep

1
kill $(ps aux | grep "$@" | grep -v "grep" | awk '{print $2}');

or add this to your .bash_aliases file to use it more conveniently

1
ka () { kill $(ps aux | grep "$@" | grep -v "grep" | awk '{print $2}'); }

Constrain Grep Line Output

Grep and return X (40 in this case) characters before and after result per line This helps to avoid having grep results that return extremely long lines which makes it difficult to parse the output.

1
egrep -Rso '.{0,40}wna4{0,40}' ./*

VI

Save a file using sudo when you currently do not currently have permissions

1
$:%!sudo tee %

Comments