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:
This probably only works without modifications in RHEL/CentOS/Fedora.
This command takes the content of a Parcellite-managed clipboard manager and add one level of indentation to it. It may be useful to indent a block of code which will enter inside another, already indented one but I use it mostly to indent code I will post in Stack Overflow questions and answers.
This command will find the highest context switches on a server and give you the process listing.
- The last sed expression ensures the unicast/multicast bit is set to zero
- The greedy space replacements are for portability across UNIX seds (note there's TWO spaces and not just one, as this web shows, in s/^ */)
This makes your commandlinefu.com's favorites appear as most recent commands in your history.
Remove old kernels (*-generic and *-generic-pae) via apt-get on debian/ubuntu based systems. Tested on ubuntu 10.04 - 12.04.
Appends the input file with the date format YYYY-MM-DD.bak. Also runs silently if you remove the -v on the cp at the end of the function.
Extract all href links from an HTML document with sed and grep
*I run this with byobu as as a custom status bar entry that runs every 10 seconds by putting it in a script here:
.byobu/bin/10_update_windows
There's no output to stdout, so nothing is displayed on the status bar.
*Presumes that #{pane_title} is set to the hostname or prompt containing the host name. In my case, it's in this format:
$USER@$HOSTNAME:$PWD
The sed commands may need to be modified if your pane_title is different.
*If you want to strip out a common part of a hostname, add the following before '| uniq'
-e 's/[COMMON PART]//'
I use that to strip out the domain of the servers I connect to, leaving the subdomain.
Use if you want to include untrusted literal strings in your grep regexes.
I use it to list all mounts below a directory:
dir=/mnt/gentoo; cat /proc/mounts |awk '{print $2}' |egrep "^$(egrep_escape "$dir")(/|$)"
/mnt/gentoo
/mnt/gentoo/proc
/mnt/gentoo/sys
/mnt/gentoo/dev
/mnt/gentoo/home
Works even if $dir contains dangerous characters (e.g. comes from a commandline argument).
Use sed to color the output of a human-readable dmesg output
Get a list of all the unique hostnames from the apache configuration files. Handy to see what sites are running on a server. When i saw the command i had some ideas to make it shorter. Here is my version.
I improved a bit on the original by only using sed and extracting the quote with a matching group.
Use -nE for sed on Mac OSX
Use -nr for sed on Linux.
Warning! The quotes from Borat are definitely offensive.