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:
Lists all packages in "rc" state and purge them one at a time.
emerge,apt-get,yum... all update your system. This will at some point replace either a runtime dependency or a process (which is still running).
This oneliner will list what processes need to be restarted
Of course, this command must be executed at a GRID User Interface
lhcb - name of your VO, substitute it with the one you are interested it.
Often you need to find the files that are taking up the most disk space in order to free up space asap. This script can be run on the enitre filesystem as root or on a home directory to find the largest files.
This works only with GNU date.
In solaris the command:
date +%s
doesn't work.
You can try using the following instead:
nawk 'BEGIN {print srand()}'
should give the same output as date +%s under Solaris.
this will dump a list of domains one per line into a text file
Get just the IP address for a given hostname. For best results, make this a function in your shell rc file so that it can be used for things like traceroute:
Titus:~$ traceroute `getip foo.com`
traceroute to 64.94.125.138 (64.94.125.138), 64 hops max, 52 byte packets
first greps syslog for certain events (grep xxxx messages) then displays the 1st 2nd and 3rd fields (-f 1,2,3) seperated by space(-d ' ')
Show all columns except 5th. This might help you save some typing if you are trying to exclude some columns from the output.
While going through the source code for the well known ps command, I read about some interesting things.. Namely, that there are a bunch of different fields that ps can try and enumerate for you. These are fields I was not able to find in the man pages, documentation, only in the source.
Here is a longer function that goes through each of the formats recognized by the ps on your machine, executes it, and then prompts you whether you would like to add it or not. Adding it simply adds it to an array that is then printed when you ctrl-c or at the end of the function run. This lets you save your favorite ones and then see the command to put in your .bash_profile like mine at : http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html
Note that I had to do the exec method below in order to pause with read.
t ()
{
local r l a P f=/tmp/ps c='command ps wwo pid:6,user:8,vsize:8,comm:20' IFS=' ';
trap 'exec 66
exec 66 $f && command ps L | tr -s ' ' >&$f;
while read -u66 l >&/dev/null; do
a=${l/% */};
$c,$a k -${a//%/} -A;
yn "Add $a" && P[$SECONDS]=$a;
done
}
Can be used in a firewall script, e.g. to avoid logging broadcast packtes.
Get the hour and greet the user!
Make sure you add this to your bashrc, for a pleasant hacking experience!