These are just a few tricks that have come in handy lately that I thought I’d pull out of my .bash_profile and stick on a web page.


This first one is a simple, universal shortcut for getting lists of files inside of various archive formats. Not that it’s terribly hard to do (tar tvf file.tgz), but why not just create one command to rule them all (and make it really short)? This is inspired by the extract function, which does similar for extracting files. I don’t know offhand who to credit with that, but you can find it in the bash-it distribution.

# ls archives (inspired by `extract`)
lsz() {
	if [ $# -ne 1 ]
		echo "lsz filename.[tar,tgz,gz,zip,etc]"
		return 1
	if [ -f $1 ] ; then
		case $1 in
			*.tar.bz2|*.tar.gz|*.tar|*.tbz2|*.tgz) tar tvf $1;;
			*.zip)  unzip -l $1;;
			*)      echo "'$1' unrecognized." ;;
		echo "'$1' is not a valid file"

Put that in your .bash_profile and next time you want to know what’s in an archive, just type lsz filename.tgz (think “list zip”). It currently works with zip and tar (including gzip, and bzip) files. Plenty of room to add more filetypes if you have other compression/archiving formats.


This one is mostly in Ruby because I go down rabbit holes any time I start playing with sed and awk. It’s an alias that lets you scan running processes and quickly find the pid and name.

# updated per Lri's comment
alias psgrep="ps -Aco pid,comm | sed 's/^ *//'| sed 's/:/ /'|grep -iE"

It accepts a partial, case-insensitive search string, or you can use regex (grep extended), like this: psgrep 'growl$' to match “growl” but not “growlhelper.” I use a similar trick for quickly finding and killing processes with an interactive menu called fk.


I love this one. It opens the current directory or a specified file in LaunchBar, ready for action. Hit tab and you can quickly copy, move, run a Service on it, open it in an app… whatever’s handy.

# Select the current directory in launchbar, optionally a file
lb () {
	if [[ $# = 1 ]]; then
		[[ -e "$(pwd)/$1" ]] && open "x-launchbar:select?file=$(pwd)/$1" || open "x-launchbar:select?file=$1"
		open "x-launchbar:select?file=$(pwd)"


If you use Gist and the command line, you probably have “jist” installed. If not, run gem install jist and make your life easier. This extremely short alias is great for popping a clipboard straight to a public gist and opening the link in your browser.

alias pbgist="jist -Ppo"


chgext batch changes the extension of all of the specified files in a directory. It takes two arguments, first the original extension, then the extension to replace it with. For example chgext html php will turn a directory of HTML files into PHP files. Magic.

I had to give this one a longer name because I don’t use it so often that I would remember a clever short one. chg+ TAB is easy enough for me to find this when I need it.

# batch change extension (fix from Lri, again)
chgext() {
	for file in *.$1 ; do mv "$file" "${file%.$1}.$2" ; done


This last one isn’t anything new, but it’s extremely useful (at least for web developers), so I figured I’d mention it. It calls qlmanage, the command line interface for Quick Look, and opens a Quick Look preview of whatever file you run it on.

alias ql="qlmanage -p &>/dev/null"

Someday I’ll actually get my entire dotfile setup onto GitHub, but don’t hold your breath.

Ryan Irelan has produced a series of shell trick videos based on posts. Readers can get 10% off using the coupon code TERPSTRA.