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.


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:



2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.




Commands using ssh from sorted by
Terminal - Commands using ssh - 284 results
sox Klaxon.mp3 -t wav - |ssh thelab@company.com paplay
2010-07-29 23:23:39
User: camocrazed
Functions: ssh

This will allow you to convert an audio file to wav format, and send it via ssh to a player on the other computer, which will open and play it there. Of course, substitute your information for the sound file and remote address

You do not have to use paplay on the remote end, as it is a PulseAudio thing. If the remote end uses ALSA, you should use aplay instead. If it uses OSS, you should berate them about having a lousy sound system. Also, you're not limited to transmitting encoded as wav either, it's just that AFAIK, most systems don't come with mp3 codecs, but will play wav files fine.

If you know SoX is installed on the remote end and has mp3 codecs, you can use the following instead:

cat Klaxon.mp3 |ssh thelab@company.com play -t mp3 -

this will transmit as mp3. Again, use your specific information. if you're not playing mp3s, use another type with the -t option

ssh -C -Y -l$USER xserver.mynet.xx 'Xnest -geometry 1900x1150 -query localhost'
ssh-keygen -f ~/.ssh/id_rsa -p
2010-07-19 12:53:35
User: darkfader
Functions: ssh ssh-keygen

Protects your secret identity with a passphrase.

OSX 10.6 automatically does key forwarding and can store the passphrase in the keychain.

For other OSes, use ssh -A or set ForwardAgent in ssh_config to enable forwarding. Then use ssh-agent/ssh-add.

for host in host1 host2 host3; do ssh -n user@$host <command> > $host.log & done; wait
2010-07-14 14:55:31
User: cout
Functions: host ssh

Ssh to host1, host2, and host3, executing on each host and saving the output in {host}.log.

I don't have the 'parallel' command installed, otherwise it sounds interesting and less cryptic.

ssh-keygen -R <the_offending_host>
2010-07-11 19:37:24
User: bunam
Functions: ssh ssh-keygen
Tags: sed

In this case it's better do to use the dedicated tool

dd if=/dev/zero bs=4096 count=1048576 | ssh user@host.tld 'cat > /dev/null'
2010-06-08 18:49:51
User: atoponce
Functions: dd ssh
Tags: ssh dd

The above command will send 4GB of data from one host to the next over the network, without consuming any unnecessary disk on either the client nor the host. This is a quick and dirty way to benchmark network speed without wasting any time or disk space.

Of course, change the byte size and count as necessary.

This command also doesn't rely on any extra 3rd party utilities, as dd, ssh, cat, /dev/zero and /dev/null are installed on all major Unix-like operating systems.

ssh host -l user $(<cmd.txt)
2010-06-04 17:47:00
User: recursiverse
Functions: host ssh

Much simpler method. More portable version: ssh host -l user "`cat cmd.txt`"

perl -e 'system @ARGV, <STDIN>' ssh host -l user < cmd.txt
2010-06-04 17:27:20
User: recursiverse
Functions: host perl ssh

I was tired of the endless quoting, unquoting, re-quoting, and escaping characters that left me with working, but barely comprehensible shell one-liners. It can be really frustrating, especially if the local and remote shells differ and have their own escaping and quoting rules. I decided to try a different approach and ended up with this.

ssh -fY user@REMOTESERVER firefox -no-remote
2010-06-03 07:24:07
User: KoRoVaMiLK
Functions: ssh

Actually 'firefox' is a script that then launches the 'firefox-bin' executable. You need to specify the 'no-remote' option in order to launch remote firefox instead of your local one (this drove me crazy time ago)

mysqldump -q --skip-opt --force --log-error=dbname_error.log -uroot -pmysqlpassword dbname | ssh -C user@sshserver 'cd /path/to/backup/dir; cat > dbname.sql'
2010-05-29 23:06:04
User: esplinter
Functions: cat ssh

backup big mysql db to remote machine over ssh. "--skip-opt" option is needed when you can?t allocate full database in ram.

echo 'Host or User@Host?:'; read newserver && ssh-keygen -N "" -t rsa -f ~/.ssh/id_rsa ; ssh $newserver cat <~/.ssh/id_rsa.pub ">>" ~/.ssh/authorized_keys ; ssh $newserver
2010-05-07 06:24:53
User: alf
Functions: cat echo read ssh ssh-keygen
Tags: ssh ssh-keygen

Some servers don't have ssh-copy-id, this works in those cases.

It will ask for the destination server, this can be IP, hostname, or user@hostname if different from current user.

Ssh keygen will let you know if a pubkey already exists on your system and you can opt to not overwrite it.

xterm -display :12.0 -e ssh -X user@server &
2010-04-22 10:29:24
User: vishalce
Functions: ssh

First of all you need to run this command.

X :12.0 vt12 2>&1 >/dev/null &

This command will open a X session on 12th console. And it will show you blank screen. Now press Alt + Ctrl + F7. You will get your original screen.

Now run given command "xterm -display :12.0 -e ssh -X user@remotesystem &". After this press Alt + Ctrl + F12. You will get a screen which will ask you for password for remote linux system. And after it you are done. You can open any window based application of remote system on your desktop.

Press Alt + Ctrl + F7 for getting original screen.

ssh user@<source_host> -- tar cz <path> | ssh user@<destination_host> -- tar vxzC <path>
ssh root@host1 "cd /somedir/tocopy/ && tar -cf - ." | ssh root@host2 "cd /samedir/tocopyto/ && tar -xf -"
2010-04-16 06:48:47
User: peshay
Functions: ssh

Good if only you have access to host1 and host2, but they have no access to your host (so ncat won't work) and they have no direct access to each other.

ssh -o UserKnownHostsFile=/dev/null root@
2010-04-08 14:55:58
User: oernii2
Functions: ssh
Tags: ssh

you may create an alias also, which I did ;-)

alias sshu="ssh -o UserKnownHostsFile=/dev/null "

ssh -t server 'cd /etc && $SHELL'
2010-04-02 19:34:09
User: dooblem
Functions: ssh
Tags: ssh

Useful to create an alias that sends you right in the directory you want :

alias server-etc="ssh -t server 'cd /etc && $SHELL'"

ssh -q user@server
2010-03-24 12:02:55
User: KoRoVaMiLK
Functions: ssh

This allows you to skip the banner (usually /etc/issue.net) on ssh connections.

Useful to avoid banners outputted to your mail by rsync cronjobs.

ssh user@host "cat /path/to/backup/backupfile.tar.bz2" |tar jpxf -
2010-03-24 01:35:28
User: mack
Functions: ssh tar
Tags: ssh tar

Here how to recover the remote backup over ssh

tar jcpf - [sourceDirs] |ssh user@host "cat > /path/to/backup/backupfile.tar.bz2"
2010-03-24 01:29:25
User: mack
Functions: ssh tar
Tags: ssh tar

Execute it from the source host, where the source files you wish backup resides. With the minus '-' the tar command deliver the compressed output to the standar output and, trough over the ssh session to the remote host. On the other hand the backup host will be receive the stream and read it from the standar input sending it to the /path/to/backup/backupfile.tar.bz2

for I in $(mysql -e 'show databases' -u root --password=root -s --skip-column-names); do mysqldump -u root --password=root $I | gzip -c | ssh user@server.com "cat > /remote/$I.sql.gz"; done
2010-03-07 15:03:12
User: juliend2
Functions: gzip ssh

It grabs all the database names granted for the $MYSQLUSER and gzip them to a remote host via SSH.

ssh -c 'tar cvzf - -C /path/to/src/*' | tar xzf -
2010-03-02 14:15:17
Functions: ssh tar

Create tarball on stdout which is piped to tar reading from stdin all over ssh

for x in `grep server /tmp/error.log | awk '{print $3}'`; do \ t=`date "+%d-%m-%H%M%S"` ; ssh -q -t admin@$x.domain.com 'pstree -auln' > ~/snapshots/$x-$t.out \ done
2010-02-26 19:50:41
User: jrparris
Functions: awk ssh


1) Systems that send out alert emails when errors, database locks, etc occur.

2) a system that:

a) has the ability to receive emails, and has procmail installed.

b) has ssh keys set up to machines that would send out alerts.

When procmail receives alert email, you can issue a command like this one (greps and awks may very - you're isolating the remote hostname that had the issue).

This will pull process trees from the alerting machines, which is always useful in later analysis.

arecord -f dat | ssh -C user@host aplay -f dat
#INSIDE-host# ssh -f -N -R 8888:localhost:22 user@somedomain.org # #OUTSIDE-host#ssh user@localhost -p 8888#
2010-02-14 21:43:44
User: Abiden
Functions: ssh

Both hosts must be running ssh and also the outside host must have a port forwarded to port 22.

ssh "cat /tmp/backup.sql | gzip -c1" | gunzip -c > backup.sql
2010-02-14 19:09:07
User: kennethjor
Functions: gunzip ssh

I've kept the gzip compression at a low level, but depending on the cpu power available on the source machine you may want to increase it. However, SQL compresses really well, and I found even with -1 I was able to transfer 40 MiB/s over a 100 mbps wire, which was good enough for me.