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 - 302 results
ssh(){ L="\$HOME/logs/$(date +%F_%H:%M)-$USER";/usr/bin/ssh -t "$@" "mkdir -p \"${L%/*}\";screen -xRRS $USER script -f \"$L\"";}
2015-10-14 13:14:29
User: flatcap
Functions: ssh

A wrapper around ssh to automatically provide logging and session handling.

This function runs ssh, which runs screen, which runs script.


The logs and the screen session are stored on the server.

This means you can leave a session running and re-attach to it later, or from another machine.




* Log sessions on a remote server

* Transparent - nothing extra to type

* No installation - nothing to copy to the server beforehand



* Function wrapper delegating to ssh

- so nothing to remember

- uses .ssh/config as expected

- passes your command line option to ssh

* Self-contained: no scripts to install on the server

* Uses screen(1), so is:

- detachable

- re-attachable

- shareable

* Records session using script(1)

* Configurable log file location, which may contain variables or whitespace

L="$HOME" # local variable

L="\$HOME" # server variable

L="some space"



* Log dir/file may not contain '~' (which would require eval on the server)



The sessions are named by the local user connecting to the server.

Therefore if you detach and re-run the same command you will reconnect to your original session.

If you want to connect/share another's session simply run:

USER=bob ssh root@server


The command above is stripped down to an absolute minimum.

A fully expanded and annotated version is available as a Gist (git pastebin):



If you want to add timing info to script, change the command to:

ssh(){ L="\$HOME/logs/$(date +%F_%H:%M)-$USER";/usr/bin/ssh -t "$@" "mkdir -p \"${L%/*}\";screen -xRRS $USER script --timing=\"$L-timing\" -f \"$L\"";}
while true; do nc -z localhost 3333 >|/dev/null || (ssh -NfL 3333:REMOTE_HOST:5432 USER@REMOTE_HOST); sleep 15; done
2015-09-21 02:25:49
User: rxw
Functions: sleep ssh

Check if SSH tunnel is open and open it, if it isn't.

NB: In this example, 3333 would be your local port, 5432 the remote port (which is, afaik, usually used by PostgreSQL) and of course you should replace REMOTE_HOST with any valid IP or hostname. The example above let's you work on remote PostgreSQL databases from your local shell, like this:

psql -E -h localhost -p 3333
ssh -o "ProxyCommand ssh user@reachable_host -W %h:%p" user@unreacheable_host
2015-06-26 06:23:14
User: renich
Functions: ssh
Tags: ssh

This command uses the reachable_host as a proxy; redirecting your request to the unreachable_host.

The main advantage is that you need only one ssh key. You copy the public part to both servers and you can access the unreachable_host without a problem.

Also, you can put this on ~/.ssh/config to access the unreachable_host directly:

# config


ProxyCommand ssh user@reachable_host -W %h:%p

and, then, just ssh user@unreachable_host.

diff <(ssh $remote_site cat $file) $file
2015-05-09 11:11:56
User: hal8
Functions: cat diff ssh

opens the output of some command as a file so this also works with graphical editors like meld, kdiff3 etc

meld <(ssh $remote_site cat .zshrc) .zshrc
ssh user@server sudo date -s @`( date -u +"%s" )`
ssh hostname nc -l 9876
ssh-keygen -t rsa -b 4096 -f ~/.ssh/<ROLE>_rsa -C "Comment goes here"
2015-01-11 17:52:21
User: krizzo
Functions: ssh ssh-keygen
Tags: ssh-keygen

This is just a default ssh-keygen command. Prompts for a password that you can use to secure the keys more and uses a higher bit value than the default along with naming the key something other than id_rsa for better file identification.

dd if=/dev/hda | ssh root@ 'dd of=/root/server.img'
2014-10-13 13:43:47
User: suyashjain
Functions: dd ssh

By this command you can take the snapshot of you harddisk (full) and create the image , the image will be directly store on remote server through ssh. Here i am creating the image of /dev/hda and saving it at as /root/server.img.

mysqldump -pyourpass --single-transaction --master-data=2 -q --flush-logs --databases db_for_doslave |tee /home/db_bak.sql |ssh mysqladmin@slave.db.com "mysql"
2014-08-11 05:57:21
User: dragonwei
Functions: ssh tee

get master info:

head -n 40 /home/db_bak.sql |awk '$0~/MASTER_LOG_FILE/

slave server:

change master ??.

start slave

tar -vzc /path/to/cool/directory | ssh -q my_server 'tar -vzx -C /'
2014-07-31 18:42:57
User: regulatre
Functions: ssh tar

Copy a local directory to a remote server using ssh+tar (assume server is lame and does not have rsync).

tar cvzf - dir | ssh my_server 'tar xzf -'
docker ps -q | xargs -n 1 docker inspect | jq '.[0].NetworkSettings.Ports +{} | map(select(. != null)[0].HostPort) | map("-L \(.):localhost:\(.)") ' | sed -n 's/.*"\(.*\)".*/\1/p' |xargs boot2docker ssh -N
tar -cj / -X /tmp/exclude.txt | cstream -v 1 -c 3 -T 10 | ssh user@host 'tar -xj -C /backupDestination'
2014-07-21 18:52:19
User: fantleas
Functions: ssh tar

The files are automatically uncompressed when they reach the destination machine. This is a fast way to backup your server to your local computer while it's running (shutting down services is recommended).

A file named "exclude.txt" is needed at /tmp/ containing the following :


















ssh -X user@host 'DISPLAY=:0 notify-send "TEST MESSAGE."'
ssh <user>@<ip address> $(echo wmic process where \"name like \'%<process to kill>%\'\" delete)
2014-07-02 04:41:05
User: adanisch
Functions: echo ssh

Tested on Windows 8 w/SSH, Cygwin - it can be tricky to quote if you dont use the $(..) syntax to echo it back out

ssh -D 8080 -f -N srv1
2014-06-25 12:46:44
User: fr00tyl00p
Functions: ssh

Provides a SOCKS5 proxy on localhost port 8080 which will tunnel all connections through srv1 and run in the background.

ssh -o ProxyCommand="nc -X 5 -x localhost:9050 %h %p" username@remote_host
2014-06-09 08:54:58
Functions: ssh

Tunneling an SSH session through TOR for anonymity.

Using openbsd's netcat.

Tested on Ubuntu 14.04

This also works with any proxy type: http, socks4 and socks5

For http proxy, replace -X 5 with -X connect

For socks4 proxy, replace -X 5 with -X 4 (DNS leak may occur)

Proxy host defined after -x

Replace -x localhost:9050 with proxy server of your choice

ssh <source host> "cat file" | ssh <dest host> "cat - > file"
2014-05-27 12:40:08
User: thorko
Functions: ssh

Copies files between hosts which don't have access to each other. It uses a proxy host which has access to both of them.

ssh [remote-machine] "cat file" | xclip -selection c
2014-05-19 16:34:44
User: conga
Functions: ssh

ssh from local to remote and pipe output of file to the local clipboard

cat ~/.ssh/id_rsa.pub | ssh deployer@xxxxx -p 52201 'cat >> ~/.ssh/authorized_keys'
dpipe /usr/lib/openssh/sftp-server = ssh $REMOTE_HOST sshfs whatever:$LOCAL_PATH $REMOTE_PATH -o slave
2014-03-25 17:40:34
User: em
Functions: ssh

While `sshfs $REMOTE_HOST:$REMOTE_PATH $LOCAL_PATH` "pulls" a directory from the remote server to the local host, the above command does the reverse and "pushes" a directory from the local host to the remote server.

This makes use of the "slave" option of sshfs which instructs it to communicate over plain stdin/stdout and the `dpipe` tool from vde2 to connect the sftp-server stdout to the sshfs stdin and vice-versa.

ssh -NL 12345:localhost:631 username@remote_server
ssh HOST '(cd REPO_DIR && git diff --name-only HEAD | cpio -o -Hnewc --quiet)' | cpio -iduv --quiet -Hnewc
2014-02-01 18:40:31
User: ivan4th
Functions: cd cpio diff ssh
Tags: ssh git cpio

Copy changed files from remote git repository, _including binary ones_, staged and unstaged alike. Note that this command doesn't handle deleted files properly.

ssh USER@HOST cat REMOTE_FILE.mp4 | tee LOCAL_FILE.mp4 | mplayer -
2013-11-28 11:25:26
User: flatcap
Functions: cat ssh tee

Securely stream a file from a remote server (and save it locally).

Useful if you're impatient and want to watch a movie immediately and download it at the same time without using extra bandwidth.

This is an extension of snipertyler's idea.

Note: This command uses an encrypted connection, unlike the original.