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.
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:
use this command to gzip the file and write to stdout and from the stdout redirect to the another file
The thunderbird message datastores get corrupt some times causing random failures, compaction to fail and general suck in thunderbird. Removing them causes thunderbird to rebuild the indexes and makes things quick again.
This command uses the top voted "Get your external IP" command from commandlinefu.com to get your external IP address.
Use this and you will always be using the communities favourite command.
This is a tongue-in-cheek entry and not recommended for actual usage.
Many users have a personal ~/bin folder for user scripts and other miscellaneous applications they can't or don't want to add to /usr/bin. But this folder can get large and unwieldy. The above command adds ~/bin and all its subdirectories to the PATH environment variable so the scripts can be organized without changing .bashrc.
a pkcs8 key will have integer 00 at offset 4 and an rsaEncryption object at offset 9
In Mac OS 9, the "New Folder" keyboard shortcut was Command+N, but in Mac OS X this was changed to "New Finder Window" instead, with "New Folder" taking the more awkward shortcut of Command+Shift+N. This command reverses their mappings.
Removes all lines between the lines containing "" and "", including these lines itself
Sometimes when working with XML files without an graphical editor, large comment-/annotation-blocks taper the readability to walk through the file. I like to create a copy of such documents without these annotations. As the documentation itself is in documentation tags inside the annotation tags an therefore graphical editors tend to put the annotation tags in their own lines, this command removes all documentations within annotation-tags.
Does one ping to a URL or host, and echo out just the response time. I use this on, with MRTG to monitor the connections to various hosts.
Replace DB-NAME and PREFIX with your settings. MySQL username and password handled by ~/.my.cnf.
same thing as the other
Using sed to extract lines in a text file
If you write bash scripts a lot, you are bound to run into a situation where you want to extract some lines from a file. Yesterday, I needed to extract the first line of a file, say named somefile.txt.
This specific task can be easily done with this:
head -1 somefile.txt
For a more complicated task, like extract the second to third lines of a file. head is inadequate.
So, let's try extracting lines using sed: the stream editor.
My first attempt uses the p sed command (for print):
sed 1p somefile.txt
Note that it prints the whole file, with the first line printed twice. Why? The default output behavior is to print every line of the input file stream.
The explicit 1p command just tells it to print the first line .... again.
To fix it, you need to suppress the default output (using -n), making explicit prints the only way to print to default output.
sed -n 1p somefile.txt
Alternatively, you can tell sed to delete all but the first line.
sed '1!d' somefile.txt
'1!d' means if a line is not(!) the first line, delete.
Note that the single quotes are necessary. Otherwise, the !d will bring back the last command you executed that starts with the letter d.
To extract a range of lines, say lines 2 to 4, you can execute either of the following:
sed -n 2,4p somefile.txt
sed '2,4!d' somefile.txt
Note that the comma specifies a range (from the line before the comma to the line after).
What if the lines you want to extract are not in sequence, say lines 1 to 2, and line 4?
sed -n -e 1,2p -e 4p somefile.txt
also see @ http://stackoverflow.com/questions/5080988/how-to-extract-string-following-a-pattern-with-grep-regex-or-perl for tip: `grep -Po 'name="\K.*?(?=")' file.txt`
use this to avoid executing the target app
On wired connections set 'eth0' instead of 'wlan0'
Newer versions of Dropbox let you choose the location for your Dropbox folder. If you use script to put things into your Dropbox folder (todo list, screenshots, torrents etc.) but have the Dropbox folder in different locations on your other computers this lets you use the same script on all systems without having to tell it where the Dropbox folder is.