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

Figure out what shell you're running

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

Remove security limitations from PDF documents using ghostscript (for Windows)
#4345 also works under windows

Joins args together using the first arg as glue

Convert control codes to visible Unicode Control Pictures
Converts control codes and spaces (ASCII code ≤ 32) to visible Unicode Control Pictures, U+2400 ? U+2420. Skips \n characters, which is probably a good thing.

Add directory to $PATH if it's not already there
Sometimes in a script you want to make sure that a directory is in the path, and add it in if it's not already there. In this example, $dir contains the new directory you want to add to the path if it's not already present. There are multiple ways to do this, but this one is a nice clean shell-internal approach. I based it on http://stackoverflow.com/a/1397020. You can also do it using tr to separate the path into lines and grep -x to look for exact matches, like this: $ if ! $(echo "$PATH" | tr ":" "\n" | grep -qx "$dir") ; then PATH=$PATH:$dir ; fi which I got from http://stackoverflow.com/a/5048977. Or replace the "echo | tr" part with a shell parameter expansion, like $ if ! $(echo "${PATH//:/$'\n'}" | grep -qx "$dir") ; then PATH=$PATH:$dir ; fi which I got from http://www.commandlinefu.com/commands/view/3209/. There are also other more regex-y ways to do it, but I find the ones listed here easiest to follow. Note some of this is specific to the bash shell.

Block an IP address from connecting to a server
This appends (-A) a new rule to the INPUT chain, which specifies to drop all packets from a source (-s) IP address.

Write comments to your history.
A null operation with the name 'comment', allowing comments to be written to HISTFILE. Prepending '#' to a command will *not* write the command to the history file, although it will be available for the current session, thus '#' is not useful for keeping track of comments past the current session.

history autocompletion with arrow keys
This will enable the possibility to navigate in the history of the command you type with the arrow keys, example "na" and the arrow will give all command starting by na in the history.You can add these lines to your .bashrc (without &&) to use that in your default terminal.

Using Git, stage all manually deleted files.
You'll probably want to pass in the -rf options if you have to delete a directory or something.


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: