Commands by postrational (5)

  • Use this BASH trick to create a variable containing the TAB character and pass it as the argument to sort, join, cut and other commands which don't understand the \t notation. sort -t $'\t' ... join -t $'\t' ... cut -d $'\t' ... Show Sample Output

    sort -t $'\t' -k 2 input.txt
    postrational · 2010-07-11 12:58:51 3
  • There is a common command for outputting a field or list of fields from each line in a file. Why wouldn't you just use cut?

    cut -f 1 three-column.txt > first-column.txt
    postrational · 2010-07-11 10:13:45 5
  • Performs a reverse DNS lookup, variants include: nslookup or: host Show Sample Output

    dig -x
    postrational · 2009-09-28 15:13:34 3
  • Date-time format: YYYY-MM-DD HH:MM:SS Show Sample Output

    export HISTTIMEFORMAT='%F %T '
    postrational · 2009-09-26 17:13:23 7
  • Checks the Gmail ATOM feed for your account, parses it and outputs a list of unread messages. For some reason sed gets stuck on OS X, so here's a Perl version for the Mac: curl -u username:password --silent "" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | perl -pe 's/^<title>(.*)<\/title>.*<name>(.*)<\/name>.*$/$2 - $1/' If you want to see the name of the last person, who added a message to the conversation, change the greediness of the operators like this: curl -u username:password --silent "" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | perl -pe 's/^<title>(.*)<\/title>.*?<name>(.*?)<\/name>.*$/$2 - $1/' Show Sample Output

    curl -u username:password --silent "" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | sed -n "s/<title>\(.*\)<\/title.*name>\(.*\)<\/name>.*/\2 - \1/p"
    postrational · 2009-09-07 21:56:40 45

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

check open ports without netstat or lsof

Delete an IPtable rules based on row number

Bind a key with a command
the -x option is for binding to a shell command

Recursively create a TAGS file for an entire source tree. TAGS files are useful for editors like Vim and Emacs

Generate a random left-hand password
Generates a random 8-character password that can be typed using only the left hand on a QWERTY keyboard. Useful to avoid taking your hand off of the mouse, especially if your username is left-handed. Change the 8 to your length of choice, add or remove characters from the list based on your preferences or kezboard layout, etc.

calulate established tcp connection of local machine
If you want prepend/append text just wrap in echo: $echo Connected: `netstat -an|grep -ci "tcp.*established"`

Detach a process from the current shell
Continue to execute the command in background even though quitting the shell.

Lookup hostname for IP address

Download all Delicious bookmarks

Trim png files in a folder
That should be a short as it can get.

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: