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:
Returns the IP, broadcast, and subnet mask of your interfaces absent any other extraneous info.
I know it's a bit lame, but I've created an alias for this when I *quickly* want to know what a system's IP is. Small amounts of time add up :)
Cleaned up and silent with &>/dev/null at the end.
Execute commands serially on a list of hosts. Each ssh connection is made in the background so that if, after five seconds, it hasn't closed, it will be killed and the script will go on to the next system.
Maybe there's an easier way to set a timeout in the ssh options...
`mount -o remount` doesn't pick up new NFS options (eg. timeo, soft, retrans, etc) so you need to do a full mount/remount cycle. This one-liner makes it quick and easy :) Update your fstab with the new options, then run it.
The lastb command presents you with the history of failed login attempts (stored in /var/log/btmp). The reference file is read/write by root only by default. This can be quite an exhaustive list with lots of bots hammering away at your machine. Sometimes it is more important to see the scale of things, or in this case the volume of failed logins tied to each source IP.
The awk statement determines if the 3rd element is an IP address, and if so increments the running count of failed login attempts associated with it. When done it prints the IP and count.
The sort statement sorts numerically (-n) by column 3 (-k 3), so you can see the most aggressive sources of login attempts. Note that the ':' character is the 2nd column, and that the -n and -k can be combined to -nk.
Please be aware that the btmp file will contain every instance of a failed login unless explicitly rolled over. It should be safe to delete/archive this file after you've processed it.
Use as: $ s host1
Will ssh to remote host upon first invocation. Then use C-a d to detatch. Running "s host1" again will resume the shell session on the remote host. Only useful in LAN environment. You'd want to start the screen on the remote host over a WAN.
Adapted from Hack 34 in Linux Server Hacks 2nd Addition.
Remove old kernels (*-generic and *-generic-pae) via apt-get on debian/ubuntu based systems. Tested on ubuntu 10.04 - 12.04.
Use this the next time you need to come up with a reasonably random bitstring, like for a WPA/WPA2 PSK or something. Takes a continuous stream of bytes coming from /dev/urandom, runs it through od(1), picking a random field ($0 and $1 excluded) from a random line and then prints it.
This command sets the volume for the main PulseAudio "sink" (usually the ALSA output interface) to the maximum, 100% (the 0x10000 in the command). To set it to an arbitrary volume, replace 10000 with the volume you want times 100 (so 75% becomes 7500).
This returns the hardware serial number. Dell calls this the "Service Tag" and it can be used to retrieve warranty information or used for RMA / repairs.
Lots of fun to run on nfs clients when the server or network connection is having issues
Disabling an interface's multicast filter is like disabling IGMP snooping on a switch. It is useful for testing and troubleshooting.
Daemontools won't always properly reap it's children. Sometimes when you need to kill the main svscan process, you want to also clean up all of it's children. The way to do that is to send a signal to the entire process group. It is a bit tricky
Sometimes you want to see all of the systcls for a given $thing. I happened to need to easily look at all of the vm sysctls between two boxes and compare them. This is what I came up with.
See the summary.
To get most of you HDD/SSD driver you need to make sure you partition are aligned, if not the speed penalty can be up to 50% slower!
this simple one liner will check to see if each partition start sector is divided by 512
you need to change sda with your driver
if you find the one of your partitions is not aligned use gparted to move the start sector of the partition to be divided of 512
"What it actually shows is going to be dependent on the commands you've previously entered.
When you do this, bash looks for the last command that you entered that contains the substring "ls", in my case that was "lsof ...". If the command that bash finds is what you're looking for, just hit Enter to execute it. You can also edit the command to suit your current needs before executing it (use the left and right arrow keys to move through it).
If you're looking for a different command, hit Ctrl+R again to find a matching command further back in the command history. You can also continue to type a longer substring to refine the search, since searching is incremental.
Note that the substring you enter is searched for throughout the command, not just at the beginning of the command." - http://www.linuxjournal.com/content/using-bash-history-more-efficiently
When I do a major change in my entities, I want to find a way to find all my Entities names and create the commande for me.
So instead of doing ls src/Your/OwnBundle... and then do it manually, this helps a lot.
Creates a single primary partition starting at sector 0 and extending to the end of the disk. Use with care.
this work even if a partition table exist
small update for this command to work with linux kernels 3.x