Linux/SSH Commands

Basics

  • cd: change directories
  • ls: list files in current directory

SSH with iTerm/Terminal on Mac

  1. Open iTerm
  2. Enter command “SSH user@IP” (e.g. “SSH nick@138.68.43.156”
  3. Might need to also enter -p2200 for port
  4. You will be prompted for password, enter and you’ll be logged in.

How to compress a file with SSH

From main root run this command: zip -r backupfilename.zip sourcedirectory/
e.g. (from 1 directory back from public_html) zip -r public_htmlbackup9.8.18.zip public_html/

How do I uncompress a file with SSH
If a file ends in .zip (for example, file.zip), type:
unzip file.zip

If a file ends in .tar (e.g., file.tar), type:
tar -xvf file.tar

If a file ends in .gz (for example, file.gz), type:
gzip -d file.gz

Etc.

Change Host File On Mac

  1. Open iTerm, type: sudo nano /etc/hosts and then hit return.
  2. Enter your Mac administrator password and then hit return.
  3. You’re now in the Nano text editor.
  4. Use cursor to navigate to bottom of file
  5. Add your line of code i.e. 
  6. 111.222.33.111 domain.com www.domain.com

Delete files/folders

Folder: rm -rf foldername/

File: rm myFile.txt myFile1.txt myFile2.txt
All files in a folder: rm -rf *

CHMOD – Change File Permissions

Syntax: chmod -R 755 /home/user/public_html/new

Note: this changes all files and folders, which can screws things up.


RunCloud Specific

Get size for all webapps on server (runcloud.io)

Get a list of webapp directory sizes. Good to check this so we’re not using up space. More info on these commands here: https://runcloud.io/knowledgebase/articles/web-application/how-to-check-how-much-disk-space-a-web-app-is-using

  • Login to root of the server you need to know the WebApp sizes
  • Use the command: du -sch /home/* | sort -h
  • You should get a list that looks something like the below.

Get size of all files/folders for a specific webapp (runcloud.io)

Get file size list of all files/folders in a specific directory.

  • Navigation to your webapp dir of choice (login root, and basically: cd ../home/dirname/webapp)
  • If you want to list the sizes of all files in the web application directory the command is: du -sch *| sort -h

Find load issues on server

  • Server load issues need to be addressed in real-time.
  • Use the command “top -c” and then press shift+p to sort the processes by CPU usage (shift+m for memory usage), this is helpful to find which web app is taking up resources.