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 - 301 results
cat myfile.mp3 | ssh user@remotemachine "mplayer -cache 8912 -"
2011-10-22 23:06:44
User: sidis405
Functions: cat ssh

Play local mp3 file on remote machine's speakers through ssh

cat .ssh/id_rsa.pub | ssh user@server "cat >>.ssh/authorized_keys2"
ssh <user>@<host> 'mkdir -m 700 ~/.ssh; echo ' $(< ~/.ssh/id_rsa.pub) ' >> ~/.ssh/authorized_keys ; chmod 600 ~/.ssh/authorized_keys'
2011-10-03 15:59:43
User: Halki
Functions: chmod echo ssh
Tags: ssh ksh

Creates the .ssh directory on the remote host with proper permissions, if it doesnt exist. Appends your public key to authorized_keys, and verifies it has proper permissions. (if it didnt exist it may have been created with undesireable permissions).

*Korn shell syntax, may or may not work with bash

ssh -i /root/.ssh/username\@hostname -p 222 username@hostname
cat ~/.ssh/id_rsa.pub | ssh <REMOTE> "(cat > tmp.pubkey ; mkdir -p .ssh ; touch .ssh/authorized_keys ; sed -i.bak -e '/$(awk '{print $NF}' ~/.ssh/id_rsa.pub)/d' .ssh/authorized_keys; cat tmp.pubkey >> .ssh/authorized_keys; rm tmp.pubkey)"
2011-09-30 07:39:24
User: tamouse
Functions: cat ssh
Tags: ssh awk

This one is a bit more robust -- the remote machine may not have an .ssh directory, and it may not have an authorized_keys file, but if it does already, and you want to replace your ssh public key for some reason, this will work in that case as well, without duplicating the entry.

cat file.orig | ssh user1@host1 "ssh user2@host2 \"ssh user3@server3 'cat >file.dest'\""
2011-09-23 12:49:19
User: Cell
Functions: cat ssh

pub key in ./ssh/authorized_keys needed because ssh-ed ssh can't ask for the password.

ssh root@HOST tcpdump -iany -U -s0 -w - 'not port 22' | wireshark -k -i -
2011-09-13 21:10:40
User: dr3s
Functions: ssh tcpdump

analyze traffic remotely over ssh w/ wireshark

When using tcpdump, specify -U option to prevent buffering and -iany to see all interfaces.

sshmysql() { ssh -L 13306: -N $* & }
2011-09-01 10:21:55
Functions: ssh

Create a secure tunnelled connection for access to a remote MySQL database.

For example, connect with MySQL Workbench to root@

DATE=$(date +%Y-%m-%d_%H-%M-%S)-$(($(date +%N)/10000000)); HOST=ssh_host; DEST=file_dest; URL=url/screenshot_$DATE.png; import -window root png:- | ssh $HOST "cat > $DEST/screenshot_$DATE.png"; echo $URL | xclip; notify-send -u low "Title" "Message"
2011-08-13 00:40:36
Functions: date echo ssh

Requires you to have password free login to remote host ;)

Requires xclip and notify-send (If you want to put into clipboard and be notified when action is completed).

DATE=$(date +%Y-%m-%d_%H-%M-%S)-$(($(date +%N)/10000000));

HOST="ssh host of your choice";

DEST="destination folder without trailing slash";

URL="URL for file if uploaded to web enabled dir ie.

import -window root png:- | ssh $HOST "cat > $DEST/screenshot_$DATE.png";

echo $URL | xclip; notify-send -u low "Screenshot Taken" "Entire screen.\nCopied to clipboard"

ssh -C USER@HOST tar -c --exclude /proc --exclude /sys / | tar -x
ssh -f -L3389:<RDP_HOST>:3389 <SSH_PROXY> "sleep 10" && rdesktop -T'<WINDOW_TITLE>' -uAdministrator -g800x600 -a8 -rsound:off -rclipboard:PRIMARYCLIPBOARD -5 localhost
2011-07-14 05:48:06
User: johnquail
Functions: ssh

This command will:

1. open an SSH tunnel to

2. go to background

3. wait for 10 seconds for the connection

4. during the 10 seconds wait it will localy run 'rdesktop' to connect to the remote host through the created SSH tunnel.

Password-less log in can be achieved (when server allows it) by adding '-p ' to the 'rdesktop' command

ssh-keygen -C hello@world
2011-07-06 18:02:32
User: aykut
Functions: ssh ssh-keygen

Now at the end of the rsa.pub file, there is our comment like=

".................peXeuE0ytJgpQcXeR5aHlfLa8dAt0obasd hello@world"

var=host ;while ! nc -zw 1 $var 22;do sleep 1; done ; ssh user@$var
ssh USER@HOST "sudo tshark -i eth0 -f 'tcp port 80 and tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420' -w -" | wireshark -k -i -
while true; do date; ssh <YOUR HOST HERE> "echo" && echo "HOST UP" && break; sleep 60; done
ssh -R 9000:localhost:9000 you@remote-php-web-server.com
2011-05-28 09:39:16
User: nadavkav
Functions: ssh

If you need to xdebug a remote php application, which is behind a firewall, and you have an ssh daemon running on that machine. you can redirect port 9000 on that machine over to your local machine from which you run your xdebug client (I am using phpStorm)

So, run this command on your local machine and start your local xdebug client, to start debugging.

more info:


ssh tomcat-server ls -l webapp-dir | grep -- '->' | awk ' { print $(NF-2) " " $(NF-1) " " $NF; }'
2011-05-23 08:38:28
User: igorfu
Functions: awk grep ls ssh
Tags: tomcat

Tomcat webapps are often remote links

ssh -X johndoe@123.456.789
2011-05-19 21:28:25
User: evandrix
Functions: ssh

To start X11 display only on your local machine: xeyes &

Extensions to basic command: ssh -X -f user@remotehost xcalc -bg black -fg green

ssh-keygen ptaduri@c3pusas1
ssh remotehost 'dpkg --get-selections' | dpkg --set-selections && dselect install
2011-05-12 17:26:43
User: Mozai
Functions: ssh

(also works on Ubuntu) Copies the 'install,' 'hold,' 'deinstall' and 'purge' states of packages on the remote machine to be matched on the local machine. Note: if packages were installed on the local machine that were never installed on the remote machine, they will not be deinstalled by this operation.

nice -n -20 ssh SOURCE_SERVER "tail -f /var/log/httpd/access.log " | awk '{print $7}' | grep jsp | parallel 'curl TARGET_SERVER{} 2>&1 /dev/null'
2011-05-09 19:32:40
User: dennisfaust
Functions: awk grep nice ssh

This takes the stream created by apache requests containing jsp and funnels them to another server. I'm using this for simulating real time traffic. The nice command gives ssh maximum CPU cycles, awk & grep strip out everything served by apache. Putting parallel on curl is important because curl is synchronous and waits for the response. Yes, I thought about using wget but it didn't seem any easier. Also, if you figure out how to run this in the background let me know. Every time I background it it stops. If you have multiple front end servers just run multiple instances of this.

ssh -l <username> <server>
ssh vm-user@`VBoxManage guestproperty get "vm-name" "/VirtualBox/GuestInfo/Net/0/V4/IP" | awk '{ print $2 }'`
2011-05-04 18:01:36
User: lucasrangit
Functions: awk get ssh

Booting the VM headless via VBoxHeadless requires knowledge of the VM's network in order to connect. Using VBoxManage in this way and you can SSH to the VM without first looking up the current IP, which changes depending on how you have your VM configured.

Diff files over SSH: ssh [login]@[host] "cat [remote file]" | diff - "[local file]"
2011-04-28 16:59:56
User: dennisfaust
Functions: diff ssh

Sometimes you need to compare two config files on different servers. Put the file names into the above script and let 'er rip.

pbpaste | ssh user@hostname pbcopy
2011-04-24 16:30:48
User: DavidLudwig
Functions: ssh
Tags: ssh osx clipboard

This uses ssh to transfer the contents of one Mac's clipboard to another's. This only works with plain text, sadly. Trying to transfer images will just clear out the remote machine's clipboard, and rich text will be converted to plain text. Using the "Remote Login" must be enabled on the remote machine (via System Preferences' Sharing panel) for this to work.