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:



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 - 297 results
cat ~/.ssh/id_rsa.pub | ssh user@host '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 user@host1 sudo cat /dir1/file1) <(ssh -t user@host2 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 / root@NEWHOST:/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 user@host 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 user@remote_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 login@server "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 -
ssh-keygen -l -f [pubkey] | cut -d ' ' -f 2 | tr -ds '\n:' ''
ssh-copy-id host
2012-07-24 08:43:41
Functions: ssh

If the username on the remote host is the same as on the local machine you can omit the username.

echo "properly_escaped_command" | ssh user@host $(< /dev/fd/0)
2012-07-18 10:36:07
User: trantorvega
Functions: echo ssh

It executes commands as arguments to ssh, avoiding problematic shell expansions, without the need of writing the commands in question to a temporary file, just reading them from STDIN.

cat ~/.ssh/id_rsa.pub | ssh [email protected] "mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys"
2012-07-18 04:41:55
Functions: cat ssh

chmod authorized_keys so you don't get "Authentication refused: bad ownership or modes for file /home/user/.ssh/authorized_keys"

cat ~/.ssh/id_rsa.pub | ssh [email protected] "mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys"
2012-07-18 04:41:54
Functions: cat ssh

chmod authorized_keys so you don't get "Authentication refused: bad ownership or modes for file /home/user/.ssh/authorized_keys"

tar cvzf - /folder/ | ssh [email protected] "dd of=/dest/folder/file.tar.gz"
2012-07-13 17:54:51
User: kruspemsv
Functions: ssh tar

You can ran this also with cat for example:

tar zcvf - /folder/ | ssh [email protected] "cat > /dest/folder/file.tar.gz"

Or even run other command's:

tcpdump | ssh [email protected] "cat > /tmp/tcpdump.log"
cat .ssh/id_rsa.pub | ssh user@server 'cat >> ~/.ssh/authorized_keys2'
2012-07-12 15:42:10
User: er0k
Functions: cat ssh

for passwordless login

ssh [email protected] "> ~/.bash_history"
2012-07-09 14:29:22
User: maxadamo
Functions: ssh

Only from a remote machine:

Only access to the server will be logged, but not the command.

The same way, you can run any command without loggin it to history.

ssh user@localhost will be registered in the history as well, and it's not usable.