What's this?

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/

Get involved!

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.

Universal configuration monitoring and system of record for IT.

Stay in the loop…

Follow the Tweets.

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

Subscribe to the feeds.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags



Commands using ssh from sorted by
Terminal - Commands using ssh - 304 results
ssh -f -L3307: -N -t -x [email protected] sleep 600 ; mk-table-sync --execute --verbose u=root,p=xxx,h=,P=3307 u=root,p=xxx,h=localhost
2009-09-04 16:54:25
Functions: sleep ssh

I wanted to keep a backup of my company database server on my local homeserver. After I found maatkit to sync databases, everything except security seemed fine. SSH takes care of that part.

while read server; do ssh -n user@$server "command"; done < servers.txt
2009-08-29 06:52:34
User: sharfah
Functions: read ssh

The important thing to note in this command, is the "-n" flag.

ssh [email protected] [anycommand](i.e uptime,w)
2009-08-29 04:27:37
User: unixbhaskar
Functions: ssh
Tags: ssh shell

Once it is connected to the remote server by that ssh protocol,the mentioned command will start working on that server.

ssh -t hostA ssh hostB
2009-08-27 21:35:19
User: 0x89
Functions: ssh

Of course you need to be able to access host A for this ;-)

ssh middlehost "ssh -a [email protected] '> nicescript'" < nicescript
2009-08-26 20:25:12
User: 0x89
Functions: ssh
Tags: ssh scp

Stop tormenting the poor animal cat!

Also you should not that you need a private key not protected by a passphrase on middlehost that grants you access to securehost..

cat nicescript |ssh middlehost "cat | ssh -a [email protected] 'cat > nicescript'"
2009-08-25 08:11:12
User: syladmin
Functions: cat ssh
Tags: ssh scp

middlehost allows ssh access from where you are but not securehost.

Use nice ssh piping to simulate scp through A => B => C

setting up the shell function if left as an exercise for the reader. ;-)

Agent forwarding should avoid password typing.

tar -cf - /home/user/test | gzip -c | ssh [email protected] 'cd /tmp; tar xfz -'
2009-08-24 18:35:38
User: esplinter
Functions: gzip ssh tar
Tags: ssh file move

Useful to move many files (thousands or millions files) over ssh. Faster than scp because this way you save a lot of tcp connection establishments (syn/ack packets).

If using a fast lan (I have just tested gigabyte ethernet) it is faster to not compress the data so the command would be:

tar -cf - /home/user/test | ssh [email protected] 'cd /tmp; tar xf -'

ssh [email protected] \ "tcpdump -nn -i eth1 -w -" | snort -c /etc/snort/snort.conf -r -
2009-08-24 14:04:06
User: omish_man
Functions: ssh

I have a small embedded linux device that I wanted to use for sniffing my external network, but I didn't want to recompile/cross-compile snort for the embedded platform. So I used tcpdump over ssh to pass all the traffic as pcap data to a "normal" Linux system that then takes the pcap data and passes it to snort for processing.

watch -n 0.5 ssh [user]@[host] mysqladmin -u [mysql_user] -p[password] processlist | tee -a /to/a/file
2009-08-19 14:21:27
User: lunarblu
Functions: ssh tee watch

Locally watch MySQL process list update every 5s on a remote host. While you watch pipe to a file. The file out put is messy though but hey at least you have a history of what you see.

ssh-copy-id [email protected]
ssh -t [email protected] screen -x <screen name>
2009-08-02 15:39:24
User: Dark006
Functions: screen ssh

If you know the benefits of screen, then this might come in handy for you. Instead of ssh'ing into a machine and then running a screen command, this can all be done on one line instead. Just have the person on the machine your ssh'ing into run something like

screen -S debug

Then you would run

ssh -t [email protected] screen -x debug

and be attached to the same screen session.

rxvt-unicode -g 999x999 -sr -depth 32 -bg rg-ba:0000/0000/0000/dddd +sb -T irssi -n irssi -name irssichat -e ssh server.com -Xt screen -aAdr -RR irssi irssi
2009-07-30 04:53:17
User: MTecknology
Functions: screen ssh

This will launch and irssi session on your server. If it's not running, it will create the session. If it's running it'll connect to it and destroy any other connections. If compositing is available, the rxvt window will have transparency added. This window will also open maximized. Anything else this does should be easily figured out in the man pages.

knock <host> 3000 4000 5000 && ssh -p <port> [email protected] && knock <host> 5000 4000 3000
2009-07-28 14:08:01
User: din7
Functions: ssh

Knock on ports to open a port to a service (ssh for example) and knock again to close the port. You have to install knockd.

See example config file below.


logfile = /var/log/knockd.log


sequence = 3000,4000,5000

seq_timeout = 5

command = /sbin/iptables -A INPUT -i eth0 -s %IP% -p tcp --dport 22 -j ACCEPT

tcpflags = syn


sequence = 5000,4000,3000

seq_timeout = 5

command = /sbin/iptables -D INPUT -i eth0 -s %IP% -p tcp --dport 22 -j ACCEPT

tcpflags = syn

ssh -t remote_host screen -r
2009-07-23 06:15:04
User: recursiverse
Functions: screen ssh
Tags: ssh screen

Directly attach a remote screen session (saves a useless parent bash process)

remind -z1 -k'echo %s |ssh <user>@<host> "growlnotify"' ~/.reminders &
2009-07-19 17:35:30
User: mattjbarlow
Functions: ssh

Requires Linux Remind:


and Growl on the Mac:


growlnotify needs to be in the executable path on the mac.

Combined with "prowl" in the iPhone you can receive push notifications of your reminders to the iPhone.

pbpaste | ssh [email protected] 'cat > ~/my_new_file.txt'
2009-07-14 16:32:03
User: mikedamage
Functions: ssh
Tags: ssh osx clipboard

Redirects the contents of your clipboard through a pipe, to a remote machine via SSH.

ssh [email protected] 'tail --max-unchanged-stats=10 -n0 -F /var/log/auth.log ' | grep Accepted | while read l ; do kdialog --title "SSH monitor" --passivepopup "$l" 3; done
# dd if=/dev/sda | gzip -c | ssh [email protected] 'dd of=/mnt/backups/sda.dd'
tar -cj /backup | cstream -t 777k | ssh host 'tar -xj -C /backup'
2009-07-02 10:05:53
User: wires
Functions: host ssh tar

this bzips a folder and transfers it over the network to "host" at 777k bit/s.

cstream can do a lot more, have a look http://www.cons.org/cracauer/cstream.html#usage

for example:

echo w00t, i'm 733+ | cstream -b1 -t2

hehe :)

ssh -L :: -L :: @
2009-06-22 19:12:48
User: starchox
Functions: ssh

Thankfully, the ssh command allows you to specify multiple tunnels through the same server in one command.

Remeber if you want a priviliged port on your machine, you must use root or sudo account.

ssh -f -N -L 5432:talk.google.com:5222 [email protected]
2009-06-05 23:17:21
User: dcabanis
Functions: ssh
Tags: ssh

If your firewall or proxy at your location prevents connection to a particular host or port, you can use ssh to tunnel to your home server and do it there instead.

ssh $HOST -l$USER cat /REMOTE/FILE | sdiff /LOCAL/FILE -
ssh -C -X [email protected] gui_command
2009-05-21 17:52:24
User: sharfah
Functions: ssh

Run GUI apps on another machine remotely through SSH.

-C is for data compression and -X enables X11 forwarding.

clear; for i in `cat thehosts` ; do ssh $i "cat uname -a ; /etc/redhat-release; cat /proc/cpuinfo | tail -n 25 | egrep '^processor|^model name' "; free ; df -h ;done