Server, Network and Hosting ► SSH

Handy SSH Command List

I used to have a google document where I keep track of some handy SSH command list. I will refer back to the list whenever I use SSH Shell command. After some time I am no longer need the list since most of the handy commands are already bared in my mind. Now the list is here and I hope it will help you in a way especially if you are new to SSH.

Switch to a parent directory

cd ..

Switch to a previous directory

cd -

Search for a file contain specific text


To compress one file or folder to a tar file

tar -cvf xxx.tar file

To extract a tar file

tar -xvf file.tar

Download a file from server to your computer

scp username@host:/path/to/hosts/file/host_file.txt ~/desktop

IF you are not sure what is the absolute path of your computer, just open a new SSH window, type CD ~, type PWD. This will show you where is your default directory when you use SSH to the server. Simply use scp username@host:/path/to/hosts/file/host_file.txt ~ will download the file to this directory.

Upload a file from your computer to the server

scp ~/desktop/file.txt username@host:/path/to/hosts/folder

It's just the reverse way of Downloading a file from the server'

Use VI to edit a file

vi file.txt

press the "insert" key to enter edit mode.

press the "Esc" to leave the edit mode, you will still remain inside the VI editor.

List of frequently used commands for VI editor:

:q! : Exit the editor without saving.

:w : Saves the changes to the file.

:wq : Saves the changes and exits.

:# : Brings you to line number #

:$ : Brings you to the last line of the file

:0 : Brings you to the first line of the file

:/keyword : Search for the string "keyword" in the file. Press "n" to view the next search result.

Check disc space per folder:

My server disc space is growing over time because of the unknown logs somewhere in the server. Use this command to check out which folders and files consume most of the unnecessary disc space and delete them.

du --max-depth=1 | sort -n | awk 'BEGIN {OFMT = "%.0f"} {print $1/1024,"MB", $2}'

Comments © 2018

Time is precious. If you have an alternative or better way to get this done, do let us know so that we can compose this list and help more people.