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.

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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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 [email protected] -i my_openssh_key.ssh -p 9999
2013-03-10 12:37:19
User: motopig
Functions: ssh

use .ssh file to login the server

ssh <remoteuser>@<remoteserver> \ 'mysqldump -u <user> -p<password> <database>' \ | mysql -u <user> -p<password> <database>
2013-03-05 19:20:52
User: kvcrawford
Functions: ssh
Tags: mysql ssh sync

There must be no space between -p and the password

ssh [email protected] "cat /remote/music/dir/*.mp3" | mpg123 -
2013-02-15 20:03:21
User: erix
Functions: mpg123 ssh
Tags: ssh Linux mpg123

This is just a quick and dirty way to play remote audio files *locally* in your PC.

The best way is to mount the remote Music directory into the local FS, say by using sshfs:

sshfs [email protected]:/remote/music/dir/ /mnt/other_pc/

rsync -a -v --stats -e ssh /home [email protected]<newserver>:/root/
ssh [email protected] -t ssh [email protected] uuencode -m testfile1.tar - | uudecode > testfile1.tar
2013-01-28 17:06:00
User: djt78
Functions: ssh uudecode uuencode

cat didn't seem to work with binaries to well for me, the above command seemed to do the trick.

Opps should be pointed out its going through a "hop" box (which is why I was searching here in first place), only need the last bit (after the -t) if doing it directly from one box to another...

ssh -t [email protected] 'sudo bash -c "ls /var/log && cat /etc/passwd"'
ssh-copy-id [-i [identity_file]] [[email protected]]machine
cat ~/.ssh/id_rsa.pub | ssh [email protected] 'cat >> ~/.ssh/authorized_keys'
ssh -t HOSTNAME 'tail -f LOGFILE' | while read; do growlnotify -t "TITLE" -m "$REPLY"; done
for host in $HOSTNAMES; do ping -q -c3 $host && ssh $host 'command' & for count in {1..15}; do sleep 1; jobs | wc -l | grep -q ^0\$ && continue; done; kill %1; done &>/dev/null
for host in $MYHOSTS; do ping -q -c3 $H 2>&1 1>/dev/null && ssh -o 'AllowedAuthe ntications publickey' $host 'command1; command2' & for count in 1 2 3 4 5; do sleep 1; jobs | wc -l | grep -q ^0\$ && continue; done; kill %1; done
2012-11-13 23:12:27
User: a8ksh4
Functions: grep host jobs kill ping sleep ssh wc

Execute commands serially on a list of hosts. Each ssh connection is made in the background so that if, after five seconds, it hasn't closed, it will be killed and the script will go on to the next system.

Maybe there's an easier way to set a timeout in the ssh options...

diff -u <(ssh -t [email protected] sudo cat /dir1/file1) <(ssh -t [email protected] sudo cat /dir2/file2)
ssh remotehosts;date
2012-11-09 01:14:24
User: kiiwii
Functions: ssh

Run this within a steady screen session.

You can get the approximate time when the remote server went down or other abnormal behavior.

rsync -ayz -e ssh --exclude=/proc --exclude=/sys --exclude=/dev / [email protected]:/MNTDIR
2012-11-06 09:43:42
User: bones
Functions: rsync ssh

Copies the complete root-dir of a linux server to another one, where the new harddisks formated and mountet. Very useful to migrate a root-server to another one.

knife ssh name:* -x ec2-user -i ~/.ssh/aws-west.pem "hostname"
2012-11-06 00:14:01
User: rwilson04
Functions: ssh

runs the specified ssh command on all chef nodes

ssh-add ~/.ssh/KEY_PAIR_NAME.pem
2012-11-03 02:59:52
User: brockangelo
Functions: ssh ssh-add
Tags: ssh EC2

This command adds your pem key to SSH so that you no longer have to manually specify it when connecting to EC2 instances.

# you can do this:

ssh ec2-instance.amazonaws.com

# instead of this:

ssh -i ~/.ssh/KEY_PAIR_NAME.pem ec2-instance.amazonaws.com

ssh -XfC -c blowfish [email protected] Xephyr dpms -fullscreen -query localhost :5
2012-11-01 18:59:57
User: hute37
Functions: ssh
Tags: ssh X Xephyr xdmcp

ssh compresion -C option ...

on slow connection VNC performs better but in local LAN native secure X protocol is an option

ssh -t [email protected]_host tmux attach
2012-10-12 17:55:50
User: shadow_id
Functions: ssh
Tags: ssh tmux

if you use tmux and wish to automatically reattach you previously detached sessions when logging in.

cat .ssh/id_dsa.pub | ssh <HOST> "mkdir -p .ssh && tee -a .ssh/authorized_keys"
ssh [email protected] "cat path/filename.mp3" | mplayer -
sshpass -p 'sshpssword' ssh -t <sshuser>@<remotehost> "echo <sudopassword> | sudo -S <command>"
2012-09-13 20:27:13
User: dynaguy
Functions: ssh
Tags: ssh sudo sshpass

Example: remote install an application(wine).

sshpass -p 'mypssword' ssh -t [email protected] "echo 'mypassword' | sudo -S apt-get install wine"

Tested on Ubuntu.

s() { screen -d -RR -m -S "$1" -t "$USER"@"$1" ssh "$1"; }
2012-09-07 23:02:52
User: salamando
Functions: screen ssh
Tags: ssh screen Linux

Use as: $ s host1

Will ssh to remote host upon first invocation. Then use C-a d to detatch. Running "s host1" again will resume the shell session on the remote host. Only useful in LAN environment. You'd want to start the screen on the remote host over a WAN.

Adapted from Hack 34 in Linux Server Hacks 2nd Addition.

sudo ssh -D 88 -fN [email protected]
ssh -l username server.tdl "tar -czf - /home/username/public_html" | tar -xzf -