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:
Compares two versions with dpkg. It is not always obvious what version dpkg/apt will consider to be more recent. Operators include the following :
* These treat an empty version as earlier than any version: lt le eq ne ge gt.
* These treat an empty version as later than any version: lt-nl le-nl ge-nl gt-nl.
* These are provided only for compatibility with control file syntax: < > >.
This command doesn't output anything. It only returns with status 0 or 1, hence the echo "y" || echo "n" to get an output.
I use this command on my machines running VMware Server to print out the state of all registered Virtual machines.
Sometimes commands are long, but useful, so it's helpful to be able to make them permanent without having to retype them. An alternative could use the history command, and a cut/sed line that works on your platform.
history -1 | cut -c 7- > foo.sh
grep ERROR *.log
-bash: /bin/grep: Argument list too long
echo *.log | xargs grep ERROR /dev/null
queries local memcached for stats, calculates hit/get ratio and prints it out.
This runs a command continuously, restarting it if it exits. Sort of a poor man's daemontools. Useful for running servers from the command line instead of inittab.
This one-liner outputs a random number between the values given for FLOOR and RANGE.
is the runtime linker/loader for ELF binaries on Linux.
=(cmd) is a zsh trick to take the output for the command "inside" it and save it to a temporary file.
echo -e 'blah' | gcc -x c -o /dev/stdout -
pipes the C source to gcc. -x c tells gcc that it's compiling C (which is required if it's reading from a pipe). -o /dev/stdout - tells it to write the binary to standard output and read the source from standard input.
because of the the =() thing, the compiled output is stashed in a tempfile, which the loader then runs and executes, and the shell tosses the tempfile away immediately after running it.
This will cause your machine to INSTANTLY reboot. No un-mounting of drives or anything.
Very handy when something has gone horribly wrong with your server in that co-location facility miles away with no remote hands!
Suspect this works with all 2.2, 2.4 and 2.6 Linux kernels compiled with magic-syskey-request support.
If you have some textfile with an unknown encoding you can use this list to find out
see sample output
above line in .bash_profile will give you window title in putty or terminal client when you login to your remote server
The $[...] block in bash and zsh will let you do math.
This is the same as using $((...)), which also works in ksh. Of course, this is a simple, dumb wrapper and doesn't allow floating-point.
Countdown from 10 or whatever you want:)
unsets variables used by the one-liner
sets up the IFS bash variable to not be affected by whitespace and disables extra glob expansion
uses read to slurp the results of the find command into an array
selects an element of the array at random to be passed as an argument to mplayer