The filesystem and archives

INPUT · Slides

The map from the root (below `/`)

01 / 08

The top is just /

On Windows or a Mac you start from a drive or from "My Documents". Linux is different.

There is one beginning, /.

/|-- bin      commands|-- etc      settings|-- home     people's rooms|-- tmp      temporary space|-- var      things that grow\-- ...

That / is called the root, as in the root of a tree.

The /home/learner you live in is one branch of this tree.

/  ->  home  ->  learner  ->  memo.txt

Plug in a USB stick and no new drive letter appears. It grows as a branch somewhere under /mnt. The whole world being one tree is the Linux way of thinking.

02 / 08

Six is enough to remember

About twenty things line up under ls /, and these are the ones to learn first.

PlaceWhat is in it
/bincommands (the real ls and cat)
/etcsettings files
/homea room for each person
/tmptemporary space (things that may vanish)
/varthings that grow (logs and so on)
/procthe state right now (not on disk)

Here is where the names come from.

/bin   binary (a machine-code program)/etc   et cetera (the rest)/var   variable (things that change)/proc  process

This layout is roughly the same on every Linux. So on a server you have never touched, look in /etc for the settings. Learn it once and it stays useful.

03 / 08

Look at the rest just once

For the rest, knowing they exist is quite enough.

PlaceWhat it is for
/sbinadministrator commands (system binary)
/usrprograms added later (/usr/bin and so on)
/libparts programs share
/devdevices (disks, the screen, /dev/null)
/rootroot's room (not the same as /)
/mnt /mediawhere outside containers get attached
/systhe kernel's knobs
/optwhere a big piece of software goes whole

Two pairs are easy to mix up.

/       the root (the very top)/root   root's home (just a room)

The names are alike and the places are entirely different.

/bin     the tools that were there to begin with/usr/bin the tools put in later

That split comes from the disk arrangements of long ago, and today you may think of both as places where commands live.

04 / 08

/tmp is the special place anyone may write in

Look at /tmp with ls -ld and a familiar shape appears.

~ $ ls -ld /tmpdrwxrwxrwt    3 root root  80 /tmp         ^         t (the sticky bit)

The t from the end of chapter 6. It means "anyone may write, and you can only remove your own".

So /tmp is where programs put their working files.

anyone may write         -> no trouble with permissionsonly your own removable  -> nobody can break another'scleared on restart       -> forgetting to tidy up is fine

Worth remembering. Stuck for somewhere to write? /tmp.

Only for things that may vanish, though. Put something precious there and one day you will be in tears.

05 / 08

Commands are files too

This may be the biggest surprise of the chapter. Look at /bin/ls.

~ $ ls -l /bin/lslrwxrwxrwx  1 root root  7  /bin/ls -> busybox

ls turned out to be a link to busybox (links come next lesson).

~ $ ls -l /bin/busybox-rwsr-xr-x  1 root root  750792  /bin/busybox

In this environment ls, cat and grep are all one program called busybox. It looks at the name it was called by and behaves accordingly inside. A trick for fitting into a small machine.

Can you see the s standing where the x should be? That is the setuid from chapter 6.

The important part is this.

> A command is not magic; it is a file sitting in /bin.

Remember typing which ls in chapter 3? The /bin/ls that came out was the place of a file that really is there.

06 / 08

/proc is not on the disk

/proc is the strangest place of all. You read /proc/PID/stat in chapter 8.

~ $ cat /proc/uptime10.03 8.86~ $ cat /proc/uptime15.42 13.21    <- the value changed!

The contents change every time you read. It is "the state right now" in the shape of a file. The kernel makes it on the spot to show you, and there is nothing on the disk.

Here are some things you can read.

/proc/uptime      seconds since it started/proc/cpuinfo     about the CPU/proc/meminfo     about the memory/proc/version     the kernel version/proc/PID/stat    the state of that process

All readable with cat. No special tool needed, which is the pleasing part.

That is what "in Linux everything is a file" means. Devices and states alike are put into a form you can open and read. So cat and grep work on them as they are.

07 / 08

Lost? Trace it from /

After moving somewhere deep, know how to get home.

cd ~      to your own room (the same with nothing after it)cd /      to the very topcd ..     one upcd -      **back to where you just were**

That last cd - is handy.

~ $ cd /usr/bin/usr/bin $ cd -/home/learner~ $

You use it when you go and look at somewhere far off and come straight back. Two characters for "there and back".

Absolute and relative paths make more sense on this map too.

/etc/passwd    the same thing wherever you are (absolute)passwd         the passwd inside where you are (relative)

The only difference is whether it starts with /. What you did in chapter 1 takes on meaning on the map.

08 / 08

Now have a go

This is everything for the lesson.

ls /              look at the mapls -ld place      see that place itself, in one linels /etc           the list of settingscat /proc/uptime  read the state right nowwhich command     find where a tool livescd -              back to where you just were

One more word on -d.

ls /tmp     list what is inside /tmpls -ld /tmp see /tmp itself, in one line

It is the mark for looking at the container itself rather than going in. You use it to check permissions and owners.

There are places you cannot get into. Try to peep into /root and you are refused. Being refused is not a failure; that is simply how it is arranged.

Now, check the map with your own hands.