More command line handiness

[Tweet : ADN : nvALT]

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.

lsz

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.

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.

psgrep

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.

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.

lb

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.

pbgist

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

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.

ql

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 BrettTerpstra.com posts. Readers can get 10% off using the coupon code TERPSTRA.