File System Structure

If you successfully followed the tutorial in the previous post, you now have a fully-functional VM running Ubuntu 20.04 LTS. Nice!

Going forward, I will dedicate each new post in the Linux Learning Series to a narrow topic. This allows me to keep the post frequency high, and allows you to take small manageable bites from an otherwise unmanageable topic.

In these early posts I may present some information that seems out of place. I will minimize this whenever possible, and will revisit some topics several times to provide additional information.

Accessing the Terminal

To begin, click the bottom-left corner (3x3 grid), then click the “All” label on the bottom edge. This will display a list of all applications installed within your Ubuntu VM. Find the Terminal and click it. After the Terminal application launches, you will be presented with a dark window with green text. The format should look similar to this:

devil@ubuntuVM:~$

This text has a special meaning, which I will explain here. devil is the name of the active user, and ubuntuVM is the hostname of the system. It is followed by a :, then the special character ~ which represents the “home” directory of user devil, and then a special symbol $ which represents the status of the user (i.e. a regular user).

Whew! Lots of info packed into this little string of characters.

The important thing to remember is that this special string of characters is printed at the start of every line in the terminal, and it will change as you move around the system.

File System Layout

There is a special user in any Linux system called root. The root user has access to all files, all devices, and can make any change to the system. The equivalent in Windows would be Administrator.

We will become root now, so we can move freely about the system.

Enter this command to become root :

devil@ubuntuVM:~$ sudo su -
[sudo] password for devil: **************
root@ubuntuVM:~#

What happened here? What is sudo, what is su, and what’s with the hyphen? OK, time for a short diversion. I promise it will be quick.

sudo is a command used to escalate user privileges. This is useful when a regular user wants to execute some command as another user (including root).

su is the command used to change the active user to root. “su” is an abbreviation for “Super User”, also known as root. Whenever you see Super User, think root.

The - is a special option for su that performs the user switch with a clean login, resetting environmental variables and other session customizations that may be in place. Think of it like a “clean slate” start to your root session.

Now that you are root, you will notice that the special string has changed to root@ubuntuVM:~#. It looks very similar to the string earlier, except with root instead of devil, and the $ has changed to a #. The # signifies that the active user is the superuser.

Whenever you see # in a terminal, you are root and should exercise caution! You have full control and can destroy your system at will. So think carefully about what you’re doing as root. In day-to-day work, you should remain as your normal user (devil in my case) and perform the necessary one-off Super User commands using sudo.

Let’s explore.

root@ubuntuVM:~# cd /
root@ubuntuVM:/# ls -l
total 459344
lrwxrwxrwx   1 root root         7 Jun 16 21:03 bin -> usr/bin
drwxr-xr-x   4 root root      4096 Jun 16 21:25 boot
drwxrwxr-x   2 root root      4096 Jun 16 21:05 cdrom
drwxr-xr-x  19 root root      4060 Jun 16 21:27 dev
drwxr-xr-x 130 root root     12288 Jun 16 21:24 etc
drwxr-xr-x   3 root root      4096 Jun 16 21:07 home
lrwxrwxrwx   1 root root         7 Jun 16 21:03 lib -> usr/lib
lrwxrwxrwx   1 root root         9 Jun 16 21:03 lib32 -> usr/lib32
lrwxrwxrwx   1 root root         9 Jun 16 21:03 lib64 -> usr/lib64
lrwxrwxrwx   1 root root        10 Jun 16 21:03 libx32 -> usr/libx32
drwx------   2 root root     16384 Jun 16 21:03 lost+found
drwxr-xr-x   3 root root      4096 Jun 16 21:15 media
drwxr-xr-x   2 root root      4096 Feb  9 10:47 mnt
drwxr-xr-x   3 root root      4096 Jun 16 21:16 opt
dr-xr-xr-x 261 root root         0 Jun 16 21:27 proc
drwx------   4 root root      4096 Jun 16 21:38 root
drwxr-xr-x  29 root root       800 Jun 16 21:27 run
lrwxrwxrwx   1 root root         8 Jun 16 21:03 sbin -> usr/sbin
drwxr-xr-x   8 root root      4096 Feb  9 10:57 snap
drwxr-xr-x   2 root root      4096 Feb  9 10:47 srv
-rw-------   1 root root 470287360 Jun 16 21:03 swapfile
dr-xr-xr-x  13 root root         0 Jun 16 21:27 sys
drwxrwxrwt  16 root root      4096 Jun 16 21:33 tmp
drwxr-xr-x  14 root root      4096 Feb  9 10:48 usr
drwxr-xr-x  14 root root      4096 Feb  9 10:56 var

What did we just do? Let’s break it down.

First, we changed directory (using cd) to the / folder. The base folder of any Linux file system is labeled /. It contains various special sub-directories with dedicated functions. I will review a few here.

Then we listed the contents of the / directory (using ls with the -l switch to show all permissions, dates, owners, and links).

/bin and /sbin used to contain critical programs needed to bring the system up and down, and to manage processes. These days Linux is more integrated, so /bin is often symbolically linked to /usr/bin and program files are kept in one place. Symbolic links are an advanced topic that I will cover later (TO-DO REMINDER). Wherever you see an arrow, like /bin -> /usr/bin, that represents a symbolic link, which is essentially a shortcut to another location within the file system.

/boot contains all necessary files for the Linux system to start from the power-on. It includes the kernel, bootloader graphics, and some kernel module information.

/cdrom is a special folder that allows you to access a CD after it’s inserted.

/dev is a bit of an odd-ball. In Linux, all physical devices are expressed as a special file on the filesystem. /dev contains all of these special device files, and access to this folder is restricted to Super User only.

/etc is the folder where system configuration files are stored.

/home is the folder where most users have their personal files stored, inside of sub-directories with appropriate permissions.

/lib, /lib32, /lib64, and /libx32 are special directories for libraries. The transition from 32-bit to 64-bit processors created a big mess for library management in the early 2000s, so it’s common to see these separate directories. You don’t have to worry about it anymore.

/lost+found is the directory where all stray/recovered files are saved during a disk consistency check during boot.

/media is a dynamic directory similar to /cdrom, intended for browsing files on USB keys, SD cards, or other devices with internal storage.

/mnt is similar to /media, except that it’s commonly used for manually attaching storage into the system with special permissions.

/opt is the traditional directory where 3rd party packages are installed (i.e. not installed as part of the distribution’s package manager. If you followed the previous YouTube video exactly, you’ll notice it contains some files related to the VirtualBox Guest Additions.

/proc is another special directory similar to /dev/ except that it allows you to interact with the processor directory through a file interface. As an example, the special file /proc/cpuinfo will display all known information about your CPU. It is restricted to the Super User.

/root is similar to the /home directory, but dedicated to the Super User.

/run is used to store configuration for all services that start or stop at various run levels. I will cover run levels later (TO-DO REMINDER).

/snap is a special directory for snap packages, which is a pre-compiled single-file package format built by Canonical, the developers of Ubuntu.

/srv is rarely used, it contains data specific to Internet-facing services such as FTP.

/sys is similar to /proc and /dev/, and contains file representations of system-level abstractions like block devices, kernel parameters, power options, etc. It is restricted to the Super User.

/tmp is a temporary directory and is often full of randomly-named files.

/usr is the top level directory for all normal user-accessible programs and files.

/var is a directory for dynamic content that is commonly edited outside of the package manager. A common directory here is /var/www for HTML documents served by Apache or nginx.

Wrapping Up & Next Steps

That’s a lot! I will end this here, but we will spend more time working with files. In the next lesson, I will cover file creation, renaming, updating, and deletion (commonly abbreviated CRUD). I will also cover file and directory permissions.

Until then, good luck and have fun!

Newsletter

Tip Jar

If you're getting value from my writing, please support my efforts with a donation. You can donate directly using my public Ethereum address bowtieddevil.eth. Or you can use the donation button below, which works through my self-hosted BTCPay Server.
linux 

See also