KC7MM Wiki

Amateur Radio with KC7MM

User Tools

Site Tools


linuxusernet:inside_linux:linuxfs_2

A Look Inside Linux series

A series of short topics on how Linux works and how to make it work the way you want it to, which I present during the weekly sessions of the Linux User Net. The target audience is Hams who are new to Linux and want to know more about it, as well as experienced Linux users who can learn more about their chosen operating system. These are my notes for the presentations. (Russ, KC7MM)

14. The Linux file system 2: Where to find things

Introduction

Last time we talked about what the Linux file system is. We saw that Linux has a single file system, and that everything on the computer is accessed through it. By “everything” I mean all software and hardware, both installed on the host itself and external to it (such as networked hosts).

That means that, as a user, you need to know where in the file system you can find the things you use. That's our topic for today.

Instead of going over the entire file system, we'll stick to the parts that you're most likely to use. If you want to know more, there's lots of material on the Web, such as this post.

File system structure

The Linux file system has a tree structure. The single point where the tree originates is called the root directory, and is designated by a forward slash character: /.

Everything else in the tree is located in branches, or subdirectories that come off of the root. The first level of subdirectories is set by default by the system. They are designed to contain various functions a Linux system performs to do its work. For example,

  • /etc contains configuration data.
  • /home is for user data storage.
  • /dev is for devices, such as disk drives and I/O ports.
  • /var contains data used by programs.
  • /usr for application program binaries and related files.

The three-letter names of most of these directories is a result of Linux's Unix legacy.

There is no official standard for this structure or for the names of the subdirctories – that is determined by the developers of Linux distributions. However, there are many benefits to be gained by employing a common structure, and so distros tend to follow the general structure that originated in Unix, with some variations to meet specific needs.

I have yet to see a distro that doesn't have /etc and /home and /usr, along with a number of others.

Commonly-used directories

/home/<username>: Home directory for users

This is for users who are granted a login and an interactive shell – you, for example. The home directory is where users can make and store files for their own use.

  • At the time a user is created, a subdirectory of /home also is created and given the user's username. For example, a user named “rufus” would be assigned the home directory /home/rufus.
  • The user has full permissions to that directory, so can do anything with files and subdirectories.
  • Users have access to only their own home directory. They no access to other users' home direcories. This is part of the multi-user design of Linux that prevents users from interfering with each other.
  • An alternate notation for a user's home directory is a tilde character: “~”. Thus a file with the path /home/rufus/myfile can be referred to as ~/myfile by user “rufus”.

/etc for configuration

/etc is the location of system configuration files.

  • This is where the system-wide configuration is stored, things such as start-up scripts and network setup.
  • All things related to using software repositories are located in /etc.
  • Everything here is owned by the root user – ordinary users cannot change anything. You can get any temporary access you might need by using sudo, or – dangerously – by becoming root with the su command. (More about this at another time.)
  • On modern Linux systems, users generally handle configuration through command-line or graphical utilities and rarely need to directly edit configuration files. Even so, the utilities will require you to have permission to run sudo.
  • On my hosts running Debian-based distros, I often edit:
    • The /etc/hosts file to get easy access to hosts on my network using only the hostname.
    • The /etc/network/interfaces file to set a fixed IP address for the host – particularly for servers.

/dev for devices

We've seen previously how Linux enables hardware devices through device drivers that connect them to directories in the Linux file system. These directories are subdirectories of /dev.

I plan to devote another “Look inside Linux” to /dev, so I won't go into detail here. For now, I'll note that:

  • Some devices are accessible directly through their /dev directory, for example a USB port at /dev/ttyUSB0.
  • Some other devices – block devices such as disk drives – require the additional step of mounting their /dev directory to another point in the file system. This allows you to do things such as mounting a drive as a subdirectory in your home directory. For example, a solid-state-drive located at /dev/nvme0 could be mounted to and accessed through the directory ~/musicfiles

/usr for applications programs

Application programs let us do the things for which we run a computer. From email to wsjt-x, these applications are the software we work with.

The /usr directory is where the files that make up applications are installed: executables, configuration, images, documentation.

  • The binary files that execute programs are located in /usr/bin.
    • As a test, open a terminal and run which bash. The result should be /usr/bin/bash
  • The /usr/share directory contains the other components that constitute applications: documentation, default configurations, icons and other images – and more.

/var for application data

  1. /var/… subdirectories are used by programs to store their data. These generally are applications that run as services, for example:
    • Database management systems store their data (PostgreSQL, MariaDB).
    • Web servers store content: HTML pages, scripts, images, Web applications (Apache, Nginx)
    • Docker server stores images and local disk files.
  2. /var/log is where the system stores logs.

In conclusion

The Linux file system has many first-level subdirectories but, as a user and system administrator, you're likely to find yourself working with only a few of them – the ones we have covered here.

Now you know where to look for things in the file system. The next step is to understand how they are set up to work as they should. It's actually quite simple: users are given access to the bits of the file system they need to use, while being kept out of the rest of it.

We'll look at how that's accomplished in our next look inside Linux.

Return to series index

linuxusernet/inside_linux/linuxfs_2.txt · Last modified: 2022/04/13 16:03 by KC7MM