Files, directories and paths

Unit 1 of 5 in Operating systems and the command line.

You will be able to find files with absolute and relative paths and say what the main Linux directories are for.

Lesson

The shell is where you type commands

A terminal is the window. The shell is the program inside it that reads what you type and runs it. The POSIX standard describes the shell as a command language interpreter that reads its input from a file or from the command line, which means the same language works typed by hand and saved in a script.

Almost everything in this class is a command you type at a shell prompt. A defender uses it because it is fast, repeatable and can be written down and rerun.

One tree, starting at the root

Linux has a single tree of directories. The manual describes the root directory as the place where the whole tree starts. Some directories have standard jobs. /etc holds configuration files that are local to the machine. /home is usually where users' own files live, although the manual says the exact layout depends on local administration. /root is usually the home directory of the root user. /tmp holds temporary files that may be deleted with no notice. /var/log is where log files go, and /usr/bin is the main place for programs ordinary users run.

Knowing this map tells a defender where to look: settings in /etc, logs in /var/log, and anything unusual in /tmp.

Absolute and relative paths

A pathname that starts with a slash is absolute: it begins at the root. One that does not start with a slash is relative: it begins at the current working directory. Every process has a current working directory. It is inherited from the process that started it and can be changed, which is what the cd command does.

To follow a path, the system looks up each directory name in turn. If the process lacks search permission on one of the directories along the way, the lookup fails with a permission denied error. So a file can be unreachable because of a directory above it, not because of the file itself.

Key points

Sources

Practice in the labs

Get comfortable moving around and managing files. These first three labs are short and give you a terminal habit.

Knowledge check

  1. Which of these is an absolute path? Answer: /var/log/syslog. A pathname starting with a slash is absolute and begins at the root of the tree. The others begin at the current directory (path_resolution(7)).
  2. Where would you expect to find a machine's local configuration files? Answer: /etc. hier(7) describes /etc as holding configuration files local to the machine. /tmp is temporary and /usr/bin holds programs.
  3. A file you can read still gives 'permission denied' when opened by its full path. What is one possible cause? Answer: You lack search permission on a directory on the way to it. Path lookup needs search permission on each directory along the way; without it the lookup fails with 'Permission denied' even if the file itself is readable.

Back to the syllabus or see all classes.

Related