All commands (14,187)

What's this?

commandlinefu.com 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

Print info about your real user.
To get your effective user: whoami

Converts to PDF all the OpenOffice.org files in the directory
Requieres unoconv (debian package)

Redirect STDIN
Several times, I find myself hitting my up arrow, and changing the search term. Unfortunately, I find myself wasting too much time typing: $ grep kernel /var/log/messages Redirecting STDIN allows me to put the search term at the end so I less cursor movement to change what I'm searching for: $ < /var/log/messages grep kernel If you're using the emacs keyboard binding, then after you press your up arrow, press CTRL+w to erase the word. If this has already been submitted, I couldn't find it with the search utility.

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"

find an unused unprivileged TCP port
Not really better - just different ;) There's probably a really simple solution out there somewhere...

Check if a machine is online
PING parameters c 1 limits to 1 pinging attempt q makes the command quiet (or silent mode) /dev/null 2>&1 is to remove the display && echo ONLINE is executed if previous command is successful (return value 0) || echo OFFLINE is executed otherwise (return value of 1 if unreachable or 2 if you're offline yourself). I personally use this command as an alias with a predefined machine name but there are at least 2 improvements that may be done. Asking for the machine name or IP Escaping the output so that it displays ONLINE in green and OFFLINE in red (for instance).

Clear cassandra snapshots that are older than 30 days
Better than: $ nodetool clearsnapshot

Colorized grep in less
Get your colorized grep output in less(1). This involves two things: forcing grep to output colors even though it's not going to a terminal and telling less to handle those properly.

Watching Command
If you need to keep an eye on a command whose output is changing, use the watch command. For example, to keep an eye on your load average

Compare two directory trees.
This uses Bash's "process substitution" feature to compare (using diff) the output of two different process pipelines.


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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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: