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:
If the machine is hanging and the only help would be the power button, this key-combination will help to reboot your machine (more or less) gracefully.
R - gives back control of the keyboard
S - issues a sync
E - sends all processes but init the term singal
I - sends all processes but init the kill signal
U - mounts all filesystem ro to prevent a fsck at reboot
B - reboots the system
Save your file before trying this out, this will reboot your machine without warning!
Probably only works with GNU du and modern perls.
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.
Forwards localhost:1234 to machine:port, running all data through your chain of piped commands. The above command logs inbound and outbound traffic to two files.
Tip: replace tee with sed to manipulate the data in real time (use "sed -e 's/400 Bad Request/200 OK/'" to tweak a web server's responses ;-) Limitless possibilities.
Show the maximum settings in effect for PHP at the command line.
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.
This is handy to just shove into a daily cron entry. If you do use cron, make sure to escape the %d with \%d or it will fail.
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1828 0.0 0.0 5396 476 ? Ss 2008 0:00 /usr/sbin/sshd
If you have some textfile with an unknown encoding you can use this list to find out
If the 'lm' flag is present, then the CPU is 64-bit.
If no output, then CPU is 32-bit.
The value for the sort command's -k argument is the column in the CSV file to sort on. In this example, it sorts on the second column. You must use some form of the sort command in order for uniq to work properly.
This command will log you into somehost via SSH and then go into the background (-f). From there, you can point e.g. firefox at localhost:8000 as a SOCKS proxy. Autossh will use port 20000 and 20001 to send and receive test data on those ports to ensure the SSH tunnel is still running, and will try to re-start the tunnel if it goes down. Make sure you have ssh-agent running, or passwordless ssh keys distributed between the two hosts.
The ip address is of the remote machine running the vncserver. Must log in first to the router then the VNC session. Very nice if you have open-wrt or dd-wrt on your router.
wrapping the snippet in $( )& puts the whole thing in the background so you don't tie up your login session.
I think I could cut down the number of pipes here, any suggestions?
This assumes your mail log is /var/log/mail.log
From 'man netstat'
"netstat -i | -I interface [-abdnt] [-f address_family] [-M core] [-N system]
Show the state of all network interfaces or a single interface
which have been auto-configured (interfaces statically configured
into a system, but not located at boot time are not shown). An
asterisk (``*'') after an interface name indicates that the
interface is ``down''. If -a is also present, multicast
addresses currently in use are shown for each Ethernet interface
and for each IP interface address. Multicast addresses are shown
on separate lines following the interface address with which they
are associated. If -b is also present, show the number of bytes
in and out. If -d is also present, show the number of dropped
packets. If -t is also present, show the contents of watchdog
The script contains a single command:
the $15 may change for you depending on your distro, etc...
This is a nice way to kill processes.. the example here is for firefox!!! substitute firefox for whatever the process name is...