CHAPTER 9 · 7 lessons · 91 exercises

The filesystem and archives

Read the map from the root. Link things together. Pack them into one file. Check how much space is left.

This is the chapter where you read the map of what is going on below /.

There are rules to how Linux lays out its directories. Commands in /bin, settings in /etc, people's rooms in /home, temporary files in /tmp, and things that grow (logs and so on) in /var. It is much the same on every distribution, so learn it once and you will not be lost on a server you have never touched.

  • the map from the root — /bin /etc /home /tmp /var /proc
  • ln -s and ln — symbolic links and hard links
  • df and du — see what space is left, and find what is eating it
  • tar — pack several files into one
  • gzip — compress
  • /proc — read the state as of now, in the shape of a file

There are two kinds of link, and the difference between them is the peak of this chapter. A symbolic link is a note saying "look over there", and it is lost when what it points at goes. A hard link is a second name on the same contents, and remove one and the other still lives. Look at the numbers (inodes) with ls -li and you can see that the latter really is the same thing.

/proc is a slightly strange place, and not on the disk. It is "the state as of now", made and shown by the kernel on the spot, and it reads with cat. It is where you notice that the shape called a file means rather more than you thought.

Lessons in this chapter

The map from the root, and links

  1. 45The map from the root (below `/`)Roughly the same layout on every server. Remember them by their job and you will not get lost.Go to the exercises
  2. 46Make a shortcut (`ln -s`)A note saying "look over there". Lose what it points at and it is lost.Go to the exercises
  3. 47A second name on the same contents (`ln`)A name and its contents are separate things. Remove the name and the contents are still there.Go to the exercises

Pack, compress, measure

  1. 48Free space and usage (`df` and `du`)Measure it before it fills up. Find out what is eating it.Go to the exercises
  2. 49Pack it all into one (`tar`)Turn many files into one box. Carry the shape of the tree with them.Go to the exercises
  3. 50Shrink it (`gzip`)Say the same contents in less space. Learn what .tar.gz really is.Go to the exercises
  4. 51Now, in the shape of a file (`/proc`)Read files that are not on the disk. Ask the kernel directly.Go to the exercises

Next up is “The shell environment”. What happens to what you type before it ever reaches the command.