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.
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:
Strangely enough, there is no option --lines=[negative] with tail, like the head's one, so we have to use sed, which is very short and clear, you see.
Strangely more enough, skipping lines at the bottom with sed is not short nor clear. From Sed one liner :
# delete the last 10 lines of a file
$ sed -e :a -e '$d;N;2,10ba' -e 'P;D' # method 1
$ sed -n -e :a -e '1,10!{P;N;D;};N;ba' # method 2
When you've got a list of numbers each on its row, the ECHO command puts them on a simple line, separated by space. You can then substitute the spaces with an operator. Finally, pipe it to the BC program.
I'm pretty sure everyone has curl and sed, but not everyone has lynx.
Display the amount of memory used by all the httpd processes. Great in case you are being Slashdoted!
slashdot.org webserver adds an X-Bender or X-Fry HTTP header to every response!
On a Gentoo system, this command will tell you which packets you have installed and sort them by how much space they consume. Good for finding out space-hogs when tidying up disk space.
This command will generate "CHECK TABLE `db_name.table_name` ;" statements for all tables present in databases on a MySQL server, which can be piped into the mysql command. (Can also be altered to perform OPTIMIZE and REPAIR functions.)
Tested on MySQL 4.x and 5.x systems in a Linux environment under bash.
Convert comma separated files to tab separated files.
(MySQL eats tab separated files with much less instruction than comma seperated files.)
Limited, but useful construct to extract text embedded in XML tags. This will only work if bar is all on one line.
If nobody posts an alternative for the multiline sed version, I'll figure it out later...
a variation of avi4now's command - thanks by the way!
If your XML is appended to a line with a time stamp or other leading text irrelevant to the XML, then you can append a s/foo/bar/ command, like this:
sed -n /<Tag>/,/<\/Tag>/p; s/.*\(<Tag.*\)/\1/' logfile.log
Just a handy way to get all the unique links from inside all the html files inside a directory. Can be handy on scripts etc.
Save the script as: sort_file
Usage: sort_file < sort_me.csv > out_file.csv
This script was originally posted by Admiral Beotch in LinuxQuestions.org on the Linux-Software forum.
I modified this script to make it more portable.
What happens if there is more than a single space between words, or spaces and tabs? This command will remove duplicate spaces and tabs.
The "-r" switch allows for extended regular expressions. No additional piping necessary.