Linux Webserver Cheat Sheet

June 28, 2016
Category: TIL
Tags: Infrastructure, Resources, and Cheat Sheets

There is obviously a lot more than this, so I’ll add more as I encounter and use them.

Last updated on: July 6, 2016.

Connecting

  • Connecting: ssh username@serveraddress
  • Switching to root once you get in, if needed: su root

Where to find things

  • Logs: /var/log/apache2
  • Site roots: /var/www/ if a single site, /var/www/vhosts if multiple sites on virtual host infrastructure
  • Config files: /etc/apache2/sitesavailable and /etc/apache2/sitesenabled

Changing directories, creating files and directories, viewing text files

  • Changing directory: cd ~/path/to/folder
  • Going up one directory: cd ..
  • Creating files: touch filename.jpg
  • Creating directories: mkdir directory_name
  • Viewing text files: less filename.txt or cat filename.txt
  • Closing out of less: q

wget

Wget retrieves content from web servers.

Syntax:

$ wget [option] URL

Options:

  • -O - Which output file the file you are downloading should get written to.
  • -q - Quiet mode. Doesn’t show the download status and other output.

Example - Getting a file from the web:

$ wget -O /path/to/filename.json http://example.com/URL/to/filename.json

Reading the manual for commands

$ man <command>

Examples:

  • man cron
  • man date

Crontab

Cron is a time-based job scheduler in Linux and Unix. Here is my full TIL on cron.

Load your personal crontab (cron table) file:

$ crontab -e

View your personal crontab:

$ crontab -l

Syntax:

min hour day of month month day of week command
* * * * * command
0 - 59 0 - 23 1 - 31 1 - 12 0 - 6 (0 to 6 are Sunday to Saturday) shell command you want to run at that time

Examble: Download a JSON file from Quandl and overwrite GOLD.json with it Monday through Friday at 5pm server time

0 17 * * 1-5 wget -O "/path/to/quandl_data/GOLD.json" "https://www.quandl.com/api/v3/datasets/LBMA/GOLD.json"

Date

Display a date and time:

  • $ date spits out the date and time on the server
  • $ TZ=US/Pacific date spits out the server’s date and time adjusted to the Pacific timezone
  • TZ=US/Eastern date -d 'Tue Jul 5 10:43:07 PDT 2016' converts the timestamp in the -d option to the Eastern timezone.
  • date -d @1467740657 converts UNIX timestamps to something you can actually read

Eric Davis has a Simple CLI date calculator writeup on his site.

Find this post useful?

Buy me a coffeeBuy me a coffee