Commands by dcabanis (20)

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Check These Out

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Determine the version of a specific package with RPM
In this case, I'm getting the package version for 'redhat-release', but of course, this can be applied to any package installed on the filesystem. This is very handy in scripts that need to determine just the version of the package, without the package name and all the sed and grep hackery to get to the data you want. To find out all the support format strings that 'rpm --qf' supports: $ rpm --querytags

watch process stack, sampled at 1s intervals
This command repeatedly gets the specified process' stack using pstack (which is an insanely clever and tiny wrapper for gdb) and displays it fullscreen. Since it updates every second, you rapidly get an idea of where your program is stuck or spending time. The 'tac' is used to make the output grow down, which makes it less jumpy. If the output is too big for your screen, you can always leave the 'tac' off to see the inner calls. (Or, better yet--get a bigger screen.) Caveats: Won't work with stripped binaries and probably not well with threads, but you don't want to strip your binaries or use threads anyway.

Set laptop display brightness
Run as root. Path may vary depending on laptop model and video card (this was tested on an Acer laptop with ATI HD3200 video). $ cat /proc/acpi/video/VGA/LCD/brightness to discover the possible values for your display.

Rename files in batch

Find files recursively that were updated in the last hour ignoring SVN files and folders.
Find files recursively that were updated in the last hour ignoring SVN files and folders. Incase you do a full svn up on accident.

Create an SSH tunnel for accessing your remote MySQL database with a local port

access to last touched or created file with arrow_up_key immediately after displaying the file list
Display recursive file list (newest file displayed at the end) and be free to access last file in the list simply by pressing arrow_up_key i.e. open it with joe editor. BTW IMHO the list of files with newest files at the end is often more informative. Put this 'lsa' function somewhere in your .bashrc and issue $ . ~/.bashrc or $ source ~/.bashrc to have access to the 'lsa' command immediately. . (the function appends command "joe last_file_in_the_list" at the end of command history)

Pronounce an English word using
Looks up a word on, does a screen scrape for the FIRST audio pronunciation and plays it. USAGE: Put this one-liner into a shell script (e.g., ~/bin/pronounce) and run it from the command line giving it the word to say: $ pronounce lek If the word isn't found in merriam-webster, no audio is played and the script returns an error value. However, M-W is a fairly complete dictionary (better than which won't let you hear how to pronounce naughty words). ASSUMPTIONS: GNU's sed (which supports -r for extended regular expressions) and Linux's aplay. Aplay can be replaced by any program that can play .WAV files from stdin. KNOWN BUGS: only the FIRST pronunciation is played, which is problematic if you wanted a particular form (plural, adjectival, etc) of the word. For example, if you run this: $ pronounce onomatopoetic you'll hear a voice saying "onomatopoeia". Playing the correct form of the word is possible, but doing so might make the screen scraper even more fragile than it already is. (The slightest change to the format of could break it).

list block devices
Shows all block devices in a tree with descruptions of what they are.

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: