CLI

Cheatsheet of some Linux Commandlines (CLI)

SSH


Port Forwarding

Forward port 80 on your machine to port 80 on the remote server you are connecting too:

ssh -L 80:localhost:80 user@server

Forward port 80 from your machine to port 80 on 192.168.0.10 which is accessible via the server you want to connect to (server).

ssh -L 80:192.168.0.10:80 user@server


Transferring Files

SCP

SCP uses SSH to move files, it’s very similar to FTP but the connection is encrypted.

Basic sending of file from local machine to a server we’ll call “server”

scp /tmp/filename.tgz user@server:/put/file/here/.

rsync

rsync also uses ssh (by default) for transferring files to remote systems.  It has the added benefit of checking the remote system before you transfer files and only transferring files that have changed.  There are tons of options you can set, such as compressing the data on the fly, deleting things that don’t exist on the local machine off the remote one, etc.

Here is a basic rsync command:

rsync -rv --progress /tmp/dir user@server:/tmp/.

Another example that keeps the same owner/group, permissions, and file modification times:

rsync -rvpogt --progress /tmp/dir user@server:/tmp/.

This is same as above but compresses the data which is helpfull for slow connection.  Doesn’t help at all if you are trasnfering files that are already compressed.

rsync -rvpogtz --progress /tmp/dir user@server:/tmp/.


Find and Delete Files

This is how you find a look for files that end in .svn in your current directory and delete them

rm -Rf `find . -name '*.svn' `