← All lessons
Files and permissions · Lesson 1 of 8

Before you start

This course follows Command line basics. If you haven't done it, this lesson is the short version of everything you need.

The terminal is a window where you type commands; the shell is the program that runs them. In the examples, $ is the prompt, the shell's sign that it's waiting: type what comes after it and press Enter. Lines without a $ are the answer. A command is a program name, then options that change how it works (a dash and a letter, like -l), then arguments it works on: in ls -l Documents, ls lists files, -l asks for the long version and Documents is the folder.

Files live in one tree of folders (directories) starting at /, the root. A path is a file's address: /home/sam/notes.txt starts at the root and works from anywhere; notes.txt on its own means "in the folder I'm in now". ~ is your home folder, . is the current folder and .. the one above.

$ pwd
/home/sam
$ cd Documents
$ ls
notes.txt  report.txt
$ cat notes.txt
buy bread

The everyday commands: pwd shows where you are, cd moves, ls lists, cat prints a file, less pages through a long one (q quits), grep word file prints the lines that contain a word, and nano file opens a file to edit (Ctrl+O saves, Ctrl+X exits).

Wildcards stand for many names: *.txt means every name ending in .txt. Put a pattern in quotes to stop the shell expanding it. Errors print on a separate channel, and 2> /dev/null on the end of a command throws them away. To run a program or script that's in the current folder, give its path: ./backup.sh.

Practice

In $ ls -l /etc, what do you actually type?

More info

Quick reference

$The prompt: type what follows it.
cmd -option argumentHow a command is put together.
/, ~, ., ..The root, your home, here, the folder above.
pwd, cd, ls, cat, lessWhere am I, move, list, print, page through.
grep word fileLines containing a word.
nano fileEdit a file (Ctrl+O save, Ctrl+X exit).
*, 2> /dev/null, ./nameWildcard; hide errors; run something in this folder.

The other Linux courses