← All lessons
Processes and scripts · Lesson 1 of 8

Before you start

This course follows Command line basics and Files and permissions. Here's everything it uses from them.

In the examples, $ is the shell's prompt: type what comes after it and press Enter, and the lines below are what comes back. A command is a program, then options (like -l), then arguments (like a file name). Paths name files: /etc/hosts from the root, notes.txt in the current folder, ~ your home folder.

Commands you'll see again: ls lists, cat prints a file, grep word file prints the lines with a word in them, head and tail show the start and end of a file, sort sorts lines, and echo prints its arguments. | (a pipe) feeds one command's output into the next, > saves output to a file and < reads a file in as input. Ctrl+C stops whatever's running.

$ echo hello > note.txt
$ cat note.txt
hello
$ cat names.txt | sort | head -n 2
ana
ben

Scripts are text files, so you'll write them in an editor: nano hello.sh opens one, Ctrl+O saves and Ctrl+X exits.

Every file has permissions saying who may read (r), write (w) and execute (x) it, shown by ls -l as rwxr-xr-x (owner, group, others). A script needs x before it can run: chmod +x hello.sh adds it. root is the administrator account, and sudo runs one command as root when you need to touch something that isn't yours.

A few words from running servers: a server is a computer that runs programs for others, like a website, usually without a screen. SSH is how you log in to one over the network and get a terminal there, and nginx (a web server) shows up in examples as a typical program a server runs.

Practice

Show the first 5 lines of log.txt.

More info

Quick reference

$The prompt: type what follows it.
a | b, > file, < filePipe; save output; read input from a file.
head, tail, sort, grepStart, end, sorted, matching lines.
nano fileEdit a file (Ctrl+O save, Ctrl+X exit).
rwx, chmod +xRead, write, execute; make a file runnable.
root, sudoThe administrator; run one command as it.
Server, SSHA computer that serves others; logging in to one remotely.

The other Linux courses