Hide

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.

Hide

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:

Hide

News

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.
Hide

Tags

Hide

Functions

Commands using ssh from sorted by
Terminal - Commands using ssh - 294 results
ssh -NR 0.0.0.0:2222:127.0.0.1:22 user@jump.host.com
2011-03-01 23:49:28
User: mweed
Functions: ssh
11

Useful to get network access to a machine behind shared IP NAT. Assumes you have an accessible jump host and physical console or drac/ilo/lom etc access to run the command.

Run the command on the host behind NAT then ssh connect to your jump host on port 2222. That connection to the jump host will be forwarded to the hidden machine.

Note: Some older versions of ssh do not acknowledge the bind address (0.0.0.0 in the example) and will only listen on the loopback address.

ssh -t -X -A user@sshproxy ssh -X -A user@sshhost
2011-02-16 15:01:18
User: FuFighter
Functions: ssh
1

Simply makes it possible to launch any X application residing on sshhost through sshproxy and display it on your screen where ever you are.

cat tarfile.tar.gz | ssh server.com " cd /tmp; tar xvzf - directory/i/want"
2011-02-11 17:10:01
User: alf
Functions: cat ssh
Tags: ssh tar
0

This may be listed already but this command is useful to untar a specific directory to a different server.

cat LOCALFILE | ssh HOST "cat > REMOTEFILE"
2011-02-03 05:29:06
User: eataudio
Functions: cat ssh
0

Nice command for when you don't have scp available for whatever reason.

Works with binaries.

ssh-keygen -R hostname
ssh-copy-id -i .ssh/id_rsa.pub username:password@remotehost.com
ssh USER@REMOTESYSTEM arecord - | aplay -
2011-01-31 16:49:45
User: mu_mind
Functions: aplay arecord ssh
4

Record off the microphone on a remote computer and listen to it live through your speakers locally.

mysqldump -u user -p --all-databases | ssh user@host dd of=/opt/all-databases.dump
ssh -T user@server < script.sh
2011-01-10 20:09:55
User: dlebauer
Functions: ssh
4

Run local scripts on remote server. "-T Disable pseudo-tty allocation"

ssh -R 5497:127.0.0.1:22 -p 62220 user@public.ip
2010-12-29 18:44:59
User: pescio
Functions: ssh
9

host B (you) redirects a modem port (62220) to his local ssh.

host A is a remote machine (the ones that issues the ssh cmd).

once connected port 5497 is in listening mode on host B.

host B just do a

ssh 127.0.0.1 -p 5497 -l user

and reaches the remote host'ssh. This can be used also for vnc and so on.

ssh -f -L 5900:localhost:5900 your.ssh.server "x11vnc -safer -localhost -nopw -once -display :0"; vinagre localhost:5900
2010-12-29 08:41:10
User: johnquail
Functions: ssh
20

This command

1. SSH into a machine

2. Tunnels VNC port to your local computer ("-L 5900:localhost:5900")

3. Runs a single use vnc server ("x11vnc -safer -localhost -nopw -once -display :0")

4. Goes into the background ("-f")

5. Runs VNC viewer on the local computer connecting to the remote machine via the newly created SSH tunnel ("vinagre localhost:5900")

infocmp rxvt-unicode | ssh 10.20.30.40 "mkdir -p .terminfo && cat >/tmp/ti && tic /tmp/ti"
2010-12-29 00:44:49
User: mhs
Functions: ssh
Tags: terminfo
3

I frequently use this trick to send my terminal settings to HPUX and older RHEL systems. This is due to the fact that terminfo support for rxvt-unicode (my preferred terminal app) does not exist on many older Linux and Unices.

dd if=mfsbsd.iso | ssh distant.server dd of=/dev/sda
2010-12-23 09:34:33
User: gormux
Functions: dd ssh
5

Install a basic FreeBSD system on a distant server. I use this to install FreeBSD on servers that can only boot a Linux rescue system. This sytem loads on ram when booted, so it is possible to install freely. You can even install on ZFS root !

tar -czvf - /src/dir | ssh remotehost "(cd /dst/dir ; tar -xzvf -)"
ssh-keygen -l -f ~/.ssh/known_hosts
2010-12-05 04:03:07
User: atoponce
Functions: ssh ssh-keygen
Tags: ssh
10

Will return the SSH server key information for each host you have in your ~/.ssh/known_hosts file, including key size, key fingerprint, key IP address or domain name, and key type.

ssh -fND localhost:PORT USER@SSH_ENABLED_SERVER
2010-12-01 14:42:13
User: 2dvisio
Functions: ssh
4

Create a persistent remote Proxy server through an SSH channel.

ssh root@host1 ?cd /somedir/tocopy/ && tar -cf ? .? | ssh root@host2 ?cd /samedir/tocopyto/ && tar -xf -?
command | ssh myHost xsel -i --display :0
2010-11-23 19:59:22
User: wincus
Functions: command ssh
Tags: ssh bash xsel
1

This command will copy command's output into your local clipboard

ssh root@HOST tcpdump -U -s0 -w - 'not port 22' | wireshark -k -i -
2010-10-28 09:02:39
User: abb
Functions: ssh tcpdump
10

When using tcpdump, specify -U option to prevent buffering.

tar cfX - exclude_opt_weblogic . | ssh tmp-esxsb044 "cd /opt/weblogic ; tar xf -"
diff <(ssh user@host1 cat /path/to/file) <(ssh user@host2 cat /path/to/file2)
ssh user@remoteserver "PGPASSWORD='passwd' pg_dump -U user bd_name | bzip2 -zv9" | bzcat | psql -U user bd_name
ssh user@host 'gunzip - > file' < file.gz
2010-09-20 14:04:47
User: putnamhill
Functions: ssh
Tags: ssh gunzip
3

This version transfers gzipped data which is unzipped as it arrives at the remote host.

gzip -cd file.gz | ssh user@host 'dd of=~/file'
2010-09-20 11:44:19
User: twfcc
Functions: gzip ssh
-3

It is an easy method unzip a file and copy it to remote machine. No unziped file on local hard drive

ssh root@192.168.0.1 "cd /;nice -n 10 tar cvpP ?exclude={"/proc/*","/sys*","/tmp/*","/home/user/*"} /">backup.tar.gz