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:
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...
see sample output
friends don't let friends use Robocopy!
"ssh-xfer is a hackish but handy way of transferring files from remote hosts to your local computer. Firstly, you need to run a slightly modified SSH authentication agent program on your local computer. Patches are available for both OpenSSH and PuTTY, see below. If you haven't used a SSH agent program before, this article seems to be reasonable, or you can look at the OpenSSH/PuTTY docs.
You don't need any modifications to your ssh client or server programs - only the modified SSH authentication agent, and the extra ssh-xfer program."
In the sample output, I pressed ctrl+r and typed the letters las. I can't imagine how much typing this has saved me.
To save the result, redirect the output to another file.
grep -v "^$" file1 > file2
Turn off almost all of dig's output except for what you'd see in a zone file. This can also be put into ~/.digrc.
This command is somewhat similar to 'nice', but constrains I/O usage rather than CPU usage. In particular, the '-c3' flag tells the OS to only allow the process to do I/O when nothing else is pending. This dramatically increases the responsiveness of the rest of the system if the process is doing heavy I/O.
There's also a '-p' flag, to set the priority of an already-running process.
The Linux /dev/full file simulates a "disk full" condition, and can be used to verify how a program handles this situation.
In particular, several programming language implementations do not print error diagnostics (nor exit with error status) when I/O errors like this occur, unless the programmer has taken additional steps. That is, simple code in these languages does not fail safely. In addition to Perl, C, C++, Tcl, and Lua (for some functions) also appear not to fail safely.
This command install Apache 2 and other utilities on CentOS
The backslash avoids any 'rm' alias that might be present and runs the 'rm' command in $PATH instead.
In a misguided attempt to be more "friendly", some Linux distributions (or sites/etc.) alias 'rm' to 'rm -i'. Unfortunately, this trains users to expect that files won't actually be deleted until they okay it. This expectation will fail with catastrophic results when they use other distributions, move to other sites, etc., and doesn't really even work 100% even with the alias. It's too late to fix 'rm', but '\rm' should work everywhere (under bash).