Logo
Linux and some users

Linux and some users

November 20, 2024
12 min read
Table of Contents

TL;DR

In this series, I will focus mainly on learning more about Linux with you. I will try some ideas and use some commands. I always wanted to try. There are so many things I’ve always wanted to try, those what-ifs that keep popping up in my head, like what if I can turn Vim into an operating system or maybe write a script that automatically generates documentation from my cryptic Terminal keybindings, or even ping every device on the planet and map it to a location on a map but with concent.

Something about keyboards

I always like to think about it like this, using a mouse limits you to the aspect ratio of the screen, always tracking it with your eye to know where to click. Using a mouse is reactive, you see, you click. On the other hand the keyboard limits are your mind, whatever comes to your mind given it a word, shortcut, command.

using the keyboard gives you a way to bend every aspect of the system that you’re using to your well while using as little brain as possible. Think about it, something feels superior or satisfying when you see your friend at work doing everything a couple of clicks away and never bother with the cursor However, it’s just sitting there in the middle of the screen begging to be touched, no homo though.

Key-board

Linux FFS

Don’t worry, I am not that guy, it’s Files, Folders and Scripts.

Something is cool about knowing how your system works, what does each directory mean, why is there and what is so special about it, when to use and when not to.

let me draw an overview of the Linux directory structure here so you get a higher view of what we are talking about and sort of create a map inside your mind about where everything is.

Linux directory structure

Note that there’s more to it, but it is just fine for now to get your feet wet.

The root

Also known as /, This is the beginning of everything on your system, it’s the starting point where all other directories originate from, think of it as an upside-down tree, the root that holds everything in place is at the top, and the branches “directorys” at the bottom.

And since everything starts from here, it’s like the C:// in Windows, it is used for absolute path, getting you anywhere from anywhere.

An example to understand it is;

  • to go to the bin directory you type in /bin/
    • The first / meaning starts from the root
    • bin/ is just the directory

another example that you will use a lot if you like to do some tweaking to Your Linux Ricing is /home/usr/.config/ and this means root / -> home home/ -> usr /usr -> .config .config/

Enough of the root, don’t try to rm -rf /, it doesn’t give you candy as that one Reddit post said.

Bin. No, not the trash

The bin/ directory contains the executable files for most of your system’s commands and programs and in full it’s called binaries.

many basic shell command executables like ls, cp, cd…etc are in that directory.

That means if you go to that directory and choose any file of them, let’s say in my case cat and run that file, it will run the command cat.

here’s an example on my system; ./bin/cat

Mostly the programs are in binary format here and accessible by all the users in the Linux system, and we will discuss more on that later.

These are critical for the system’s basic functionality and are available in the root file system.

Dev ── Device Files

Linux treats everything as a file, even you, you’re just a file.

The dev/ directory contains special files. Contains device files that represent hardware components, like hard drives /dev/sda, terminals /dev/tty, and even virtual devices.

Some of these files might be

  • /dev/null is just a virtual file that destroys anything you toss at it, given it an error, the biggest chunk of code that you cated or anything that you want to hide for some reason. Just a black hole.

    • It is empty
    • The creation date is the same as the last boot of the device
    • The file’s UID and GID are 0
    • every user is allowed to read and write on /dev/null
    • It is a character device file which means it will act like an unbuffed device and can accept data streams
  • /dev/zero for some reason an infinite number of zeros in a file, if you need it, but why?

    • Formatting drive and filling space with zeros to override old data.
    • Creating dummy files for experiments.
    • Creating a temporary swap file.
  • /dev/random well, random.

etc and misc

etc/ Yes just a directory previously used for misc files now used for configuration files of the system and used by the sudo and system services. You’ll deal a lot with it during your Linux installation configuring the network, users, hosts ── etc.

usr ── User binaries and data

Just as the name implies, a user directory, a You directory.

The /usr directory contains data, binaries, libraries, and documentation that are not required for the basic boot process but are necessary for regular use once the system is fully operational.

It’s typically where user-level programs, libraries, and system files reside, making it a central location for resources that are not specific to any one user, but accessible to everyone.

You haven’t seen /usr/bin yet.

wha- what

usr/bin

The /usr/bin is what contains the executable files for the commands that you either downloaded, or the system did but not a very crucial part of the system, think of it as the cherry on the top, what makes it easier for you to use Linux.

I used this folder multiple times when I wanted to replicate my Arch Linux setup on my home lab, I made a text file containing the ls -a of that folder and used Pacman to install all the packages from that file directly.

usr/lib ── As for libraries

We also got the /usr/lib or libraries and it contains shared libraries and support files needed by the programs and binaries located in /usr/bin and /usr/sbin

  • Libraries: These are files that provide reusable code for executables, often with a .so (shared object) extension. For example, shared libraries like libc.so (the C standard library) are found here.

  • Support Files: This can include kernel modules, firmware, or other architecture-specific data required by programs.

usr/share ── Not online

The /usr/share directory contains architecture-independent files that are shared across programs. These are typically data files, not executables or compiled libraries.

  • Documentation: Man pages and info pages for installed software, /usr/share/man.
  • Icons and Themes: Graphical resources for the desktop environment, /usr/share/icons.
  • Locale Files: Language translations and locale data for programs, /usr/share/locale.
  • Static Data: Fonts, templates, configuration examples, and other files that don’t change based on the system’s architecture.

All of these might slightly change on your machine depending on the initial setup, the distribution you use and other factors.

Sharing is not caring

Home but nothing sweet

/home/sinmaven it’s just my directory, enough of the system. This is where all my configuration and files reside.

The home directory is a dedicated space for each user’s files and configurations. It contains individual folders for storing documents, photos, music, notes, and user-specific settings for applications. This directory provides organization and privacy, making it an essential part of a user’s workspace.

Here’s how my home folder looks like;

ls
Archive  Desktop  Documents  Downloads  Pictures  Projects  Templates  Temporary  Videos
home/sinmaven/

When creating a user, it is common practice to establish a home directory for that user. For instance, if your system has two users, Mi and Yu, their home directories would be located at /home/mi and /home/yu, respectively.

I am mi

tmp

A temporary directory that holds temporary files either made by you or the system.

But do note that the contents of the /tmp directories are deleted when your system restarts. Some Linux systems also delete files old files automatically so don’t store anything important here.

var ── Variables in a folder

The var directory is for storing runtime information like system logs, user tracking data, and caches. Since the files here are not automatically cleaned, it’s a valuable resource for system administrators to monitor system behaviour.

boot ── Boot files

The /boot directory is an important part of the file system structure. It contains the necessary files for the boot process—that is, the files that allow the computer to load the operating system when the system starts.

It contains some essential files and folders for the system;

  • Kernel Image vmlinuz: the core part of the operating system, which is responsible for interacting with hardware, managing system resources, and providing services to the user and other programs.
    • The kernel image is stored as a compressed file (e.g., vmlinuz-linux). This compressed file is loaded into memory during the boot process.
  • Initial RAM Disk initframs, initrd: The initial RAM disk is a temporary root file system loaded into memory during boot. It contains essential drivers and tools needed to mount the real root file system.
    • The initrd image is often named something like initrd.img. It’s used to load critical modules before the main file system is available.
  • Bootloader files grub: The bootloader as the name suggests is responsible for loading the kernel and allows the user to choose which operating system to boot.
  • GRUB _Grand Unified Bootloader_: This is the most common bootloader regarding Linux operating systems. The /boot folder includes the grub configurations inside the /boot/grub/ and you can customize everything about it.
  • SYSLINUX Simple Linux Loader: A lightweight bootloader designed for simpler environments like live USBs, ISO images, or embedded systems.
    • syslinux.cfg Configuration File: The syslinux.cfg file is the primary configuration file for SYSLINUX. It defines how the boot process operates and specifies kernel options, menu entries, and additional boot parameters. Located in /boot/syslinux/ (or in the root of bootable media), this file is essential for SYSLINUX’s functionality.
syslinux.cfg
default linux
prompt 0
timeout 50
ui vesamenu.c32
 
label linux
    menu label boot linux
    kernel /boot/vmlinuz-linux
    append initrd=/boot/initramfs-linux.img root=/dev/sda1 rw
/boot/syslinux/syslinux.cfg
  • DEFAULT: Specifies the default boot option if no selection is made.
  • PROMPT: Enables or disables the boot prompt (0 means no prompt).
  • TIMEOUT: Sets the delay before the default option is automatically selected.
  • UI: Specifies the menu system to use.
  • LABEL: Defines a boot menu entry.
  • KERNEL: Specifies the kernel file to load.
  • APPEND: Passes additional arguments to the kernel, such as the initial RAM disk and root file system.

boot process overview

  • bios/uefi: the firmware bios/uefi loads first when the system powers on and performs initial hardware checks.
  • bootloader: the bios/uefi loads the bootloader, grub from the master boot record (MBR) or efi partition. The bootloader reads its configuration from the /boot directory and displays the boot menu.
  • kernel loading: the bootloader loads the kernel found in /boot/vmlinuz-* and optionally the initial ram disk found in /boot/initrd.img-*, passing control to the kernel.
  • kernel initialization: the kernel initializes the system, detects hardware, and mounts the real root file system.
  • system boot: the system proceeds to start essential services and the user space, allowing you to log in and use the system.

Hacker movie boot

proc and some work

This one includes the data about the currently running processes and kernel parameters.

This folder is used in many of the Linux tools that display the current live state of the system. for example, if you want to check the CPU info you can just run cat /proc/cpuinfo or lscpu or if you want to check the memory info cat /proc/meminfo and so much more regarding the state and processes of the system.

opt ── Optional software

The /opt directory is used to store optional software or third-party applications that are not part of the default Linux distribution.

  • This includes proprietary software, large applications, or custom packages installed manually.
  • It provides a clean and organized location for software that doesn’t adhere to the standard file system hierarchy.

Root - The user, not the tree

There is the /root directory as well and it works as the home directory of the root user. So instead of /home/root, the home of the root is located at /root. Do not confuse it with the root directory /.