commandlinefu.com is the place to record those command-line gems that you return to again and again.
Delete that bloated snippets file you've been using and share your personal repository with the world. 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.
If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/
You can sign-in using OpenID credentials, or register a traditional username and password.
First-time OpenID users will be automatically assigned a username which can be changed after signing in.
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
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:
I put this line in my ~/.bashrc file (which I source via ~/.bash_profile). Now, when I need to install a package, I typed *install* instead of the longer version.
I often use this command to learn pronunciation of unfamiliar words.
I use this command to start a local Python document server over HTTP port 8888.
I often run some command that takes a while to finish. By putting the say command afterward, I get an audio notification.
Please note that this command (say) only works on Mac OS X and not Linux.
Curious about differences between /bin, /usr/bin, and /usr/local/bin? What should be in the /sbin dir? Try this command to find out.
Tested against Red Hat & OS X
I use this command (PS1) to show a list bash prompt's special characters. I tested it against A flavor of Red Hat Linux and Mac OS X
Usage:
mydir=/very/long/path/to/a/dir
cd mydir
I often need to cd where no man wants to go (i.e. long path). by enabling the shell option cdable_vars, I can tell cd to assume the destination is the name of a variable.
If you omit the function name, the command will display all definitions
If you issue the "set" command, you'll see a list of variables and functions. This command displays just those functions' names.
I often need to extract a function from a bash script and this command will do it.
For example, if you are the type who type ls very often, then
PROMPT_COMMAND=ls
will ls after every command you issue.
Place this in your .bash_profile and you can use it two different ways. If you issue 'h' on its own, then it acts like the history command. If you issue:
h cd
Then it will display all the history with the word 'cd'
I often need to know of my directory in the PATH, which one DOES NOT exist. This command answers that question
* This command uses only bash's built-in commands
* The parentheses spawn a new sub shell to prevent the modification of the IFS (input field separator) variable in the current shell
I have a directory containing log files. This command delete all but the 5 latest logs. Here is how it works:
* The ls -t command list all files with the latest ones at the top
* The awk's expression means: for those lines greater than 5, delete.
This command displays a simple menu of file names in the current directory. After the user made a choice, the command invokes the default editor to edit that file.
* Without the break statement, the select command will loop forever
* Setting the PS3 prompt is optional
* If the user types an invalid choice (such as the letter q), then the variable $f will become an empty string.
* For more information, look up the bash's select command
This command displays a list of lines that are longer than 72 characters. I use this command to identify those lines in my scripts and cut them short the way I like it.
The curl command retrieve the HTML text containing the IP address. The grep command picks out the IP address from that HTML text.
This is a simple command for jumping to the matching brace, square bracket, or parentheses. For example, it can take you from the beginning of a function to the end with one key stroke. To delete everything between the pairs of {}, [], or (), issue the command:
d%
To replace text between pairs of braces, brackets, or parentheses, issue the command:
c%
You can also use this command to find out if an opening brace has been properly closed.
Retrieve the current stock price from Yahoo Finance. The output is simply the latest price (which could be delayed). If you want to look up stock for a different company, replace csco with your symbol.
The nl command lists the contents of a file where is each line is prefixed by a line number. For more information about this command, check out its man page. I tested under Mac OS X and Xubuntu 9.04
I use terminal with black background on the Mac. Unfortunately, the default ls color for the directory is blue, which is very hard to see. By including the line above in my ~/.bash_profile file, I changed the directory's color to cyan, which is easer to see. For more information on the syntax of the LSCOLORS shell variable:
man ls
I tested this command on Mac OS X Leopard