Before we dive into the main topic, let’s first talk about the differences between Unix-based operating systems (like Linux and macOS) and non-Unix operating systems (like Windows). These differences come from how they are designed, their structure, and how they manage tasks such as user interaction, processes, and files. Let’s simplify it to make it clearer.
Differences Between Unix and Non-Unix Operating Systems:
1. Design Philosophy
Unix
- Modular Design: Unix is built around the idea of small, simple tools that can be combined to perform complex tasks. This is known as the “Unix Philosophy.”
- Everything is a File: In Unix-like systems, almost everything (devices, processes, etc.) is treated as a file. This simplifies managing hardware and user processes.
- Multitasking and Multiuser: Unix systems are designed to handle multiple users and tasks simultaneously, each with its own environment.
Non-Unix
- More Monolithic Design: Non-Unix systems tend to be more monolithic, with a focus on being user-friendly and supporting more graphical interfaces.
- Less Unified File Management: Non-Unix systems like Windows don’t treat everything as a file. For example, devices like printers or disks are managed differently.
Less Emphasis on Multiuser: While Windows supports multiuser environments, it was historically more focused on single-user desktop computing. The multiuser features came later, especially in server versions.
2. User Interface
Unix
- Command-Line Interface (CLI): Unix systems primarily rely on a command-line interface (CLI), where users type commands to interact with the system.
- Terminal-Based Interaction: Users interact with the system through a terminal, where they can run commands, write scripts, and manage processes.
Non-Unix
- Graphical User Interface (GUI): Non-Unix operating systems like Windows focus on a graphical interface. Users interact with the system using windows, icons, and menus (WIMP), making it more user-friendly, especially for non-technical users.
- Point-and-Click: Most operations are done by clicking on icons and using graphical tools instead of typing commands.
3. File System
Unix
- Hierarchical File System: Unix uses a single-rooted, hierarchical file system with directories and subdirectories. For example, all files, including system files, user files, and devices, are organized under a single root directory (/).
- Everything is a File: Devices (like printers or hard drives) are represented as files. For example, /dev/sda might represent a hard drive.
Non-Unix
- Drive-Based File System: Non-Unix systems like Windows use a drive-based system (ex- C:\, D:\) where each drive has its own file system structure.
- Less Unified: In Windows, devices are not treated as files. For example, printers or network connections are separate from the file system and managed by different system tools.
4. Security and Permissions
Unix
- Root (Administrator) Access: Unix systems have a concept of a root user (administrator) who has unrestricted access to the system.
Non-Unix
- Access Control Lists (ACLs): Windows has a different model for managing permissions, relying more on Access Control Lists (ACLs) and user roles. It is less focused on file permissions and more on broader access control.
- Administrator User: Windows also has an administrator account, but it is integrated into the system more for ease of use.
5. Process Management
Unix
- Processes as First-Class Citizens: In Unix, every task is treated as a process. The operating system can easily manage multiple processes running simultaneously (multitasking), and tools like “ps” and “top” allow users to view and manage processes.
- Forking and Piping: Unix provides easy ways for processes to interact with each other through “pipes” (|), enabling one process to pass its output as input to another process.
Non-Unix
- Less Emphasis on Process Handling: Windows and other non-Unix systems don’t treat processes with the same level of focus. While they support multitasking, the tools for managing and interacting with processes are more graphical and user-friendly.
- Limited Process Interaction: In Windows, interacting between processes (ex- passing data between programs) is more complex and not as seamless as in Unix.
6. Command-Line Interface vs GUI
Unix
- Primarily CLI-Based: Unix is traditionally command-line based, though modern Unix-like systems (like Linux) support graphical environments. However, the core power of Unix is in its terminal-based tools.
- Shell Scripting: Unix supports shell scripting to automate tasks, allowing for a high degree of customization.
Non-Unix
- Primarily GUI-Based: Non-Unix operating systems, like Windows, are designed for easy use through graphical interfaces, with command-line tools being secondary (though PowerShell is an advanced command-line interface in Windows).
7. System Architecture
Unix
- Modular and Scalable: Unix systems are highly modular and can be customized or scaled to suit different needs, from simple personal computers to large enterprise servers.
- Open Standards: Unix adheres to open standards and is open to modification, especially in open-source versions like Linux.
Non-Unix
- Monolithic and Integrated: Non-Unix systems like Windows tend to be more monolithic, meaning they are developed and maintained by a single company (Microsoft). Many of the features (GUI, file systems, etc.) are integrated into one cohesive system, without as much modularity or openness.
Now that we have some understanding about linux, we can move on to the next stage…
Understanding the Linux Device Tree
In embedded systems, we often use things like SPI, I2C, SDIO, UART, and USB. However, most onboard devices connected through SPI, I2C, Ethernet, and similar methods cannot tell the operating system that they are there. They do not have the ability to announce themselves.
USB devices are different. For example, when you connect a pen drive to a USB port, it automatically tells the operating system that it is connected. Devices that cannot do this are called platform devices.
The Problem How can we tell the Linux operating system about these platform devices?
In the past, developers used a method called the board file. Each board had its own file, and this file contained details about all the devices on the board. When the operating system started, it used this file to understand the hardware. If you added a new device to the board, you had to update the board file, recompile the operating system, and repeat this process for every board variation.
The Solution Device tree to solve this problem, the ARM community introduced the Device Tree. Instead of putting the hardware details into the operating system, they created a separate file called the Device Tree Source file.
Device Tree Source file is a text file that describes all the hardware on a board.
This file is compiled using a special program to create a binary file called the Device Tree Blob.
When the operating system starts, it reads the Device Tree Blob to understand the hardware on the board. If you make changes to the hardware, you only need to update the Device Tree Source file and compile it again. You do not need to change or recompile the operating system.
Why This is Better?
You do not need to include hardware details in the operating system anymore. It is easier to support different versions of the same board, and updating hardware details is faster and simpler.
Now, when you look inside the Linux operating system, you will find many Device Tree Blob files. Each one matches a different board. This system makes working with embedded devices much easier and more efficient.
Basic Understanding of the Linux File System Structure
Now add some basic folder structure of a Linux file system and what it means. Each folder has a specific purpose and contains certain types of files. Together, they make the system organized and easy to manage.
In a typical Linux file system, you’ll find a standard set of folders. Not all of these are necessary for the system to boot or work, but they play important roles in how Linux operates. For example, some folders hold system files needed to start your computer, others store user files, and some are meant for temporary data or system configuration.
Understanding what these folders are for can help you navigate the file system, troubleshoot issues, and make better use of Linux. So, let’s go through each folder, one by one, to see what it’s all about and what kind of files you can expect to find inside.
If I talk about some examples…
- Some directories are designed to store user commands and executables used frequently (/bin), while others are reserved for system administrators and privileged operations (/sbin).
- Certain directories, such as /boot, are crucial during the booting process, containing files like the kernel image and boot loader.
Directories like /etc hold configuration files essential for system-wide and network settings.
- This structured approach ensures that users, administrators, and processes can easily locate and interact with the necessary files for different operations. Below, we’ll explore the standard directory structure in a Linux file system, examine its purpose, and understand what kind of files and subdirectories you can expect to find in each one.
DIRECTORY DESCRIPTION bin : Essential command binaries boot : Static files of the boot loader dev : Device files etc : Host-specific system configuration lib : Essential shared libraries and kernel modules media: Mount point for removable media mnt : Mount point for mounting a file system temporarily opt : Add-on application software packages run : Data relevant to running processes sbin : Essential system binaries srv : Data for services provided by this system tmp : Temporary files usr : Secondary hierarchy var : Variable data
1. bin/
This folder holds the binaries for Linux commands that both regular users and system administrators can use. You don’t need special permissions or root access to run these commands.
It doesn’t include all Linux commands just the ones that are commonly available to everyone.
Below are some commands found in the bin/ directory:
- cat: A command used to display the contents of files, concatenate them, or send their content to standard output (usually the terminal).
- chgrp: Changes the group ownership of a file or directory.
- chmod: Modifies the access permissions of files and directories, determining who can read, write, or execute them.
- chown: Alters the ownership of files and directories, including both the user and the group.
- cp: Copies files and directories from one location to another.
- date: Displays or sets the current system date and time.
- dd: A versatile tool to copy and convert files at a low level, often used for tasks like creating bootable USBs or backing up disks.
- df: Reports available disk space on file systems, helping you monitor storage usage.
- dmesg: Displays kernel message logs, useful for debugging and understanding system boot or hardware issues.
- echo: Prints text or variables to the terminal, commonly used in scripts to display messages.
- false: A command that always returns an unsuccessful exit status, often used for testing or scripting.
- hostname: Displays or sets the system’s hostname (its network name).
- kill: Sends signals to processes, such as terminating them or instructing them to reload configuration files.
- ln: Creates hard or symbolic links between files, which act as pointers to the original files.
- login: Starts a session by authenticating a user and granting them access to the system.
- ls: Lists the contents of a directory, such as files and subdirectories.
- mkdir: Creates new directories.
- mknod: Creates special block or character device files, usually by administrators for hardware devices.
- more: Displays the contents of a text file one screen at a time, useful for long files.
- mount: Mounts file systems, allowing access to storage devices or partitions.
- mv: Moves or renames files and directories.
- ps: Shows the status of active processes, including their IDs, resource usage, and more.
- pwd: Prints the full path of the current working directory.
2. boot/
This directory contains boot-related files required for booting Linux. It may be read by the boot loader to access files like the Linux kernel image, dtb, vmLinux, and initramfs.
The boot loader accesses this directory even before the kernel boots and mounts the file system.
3. dev/
The /dev/ directory contains the “device files” in a Unix/Linux system.
You might have heard the phrase “In Unix/Linux, devices are treated like files.” This means that any type of device, whether it’s for input/output, networking, memory, serial, or parallel devices such as keyboards, mouse, or displays, is represented as a file in the system.
Each device will have an entry in this directory. For example:
- I2C devices may have entries like-
/dev/i2c-0 /dev/i2c-1
User-space applications can use these device files to access the corresponding devices.
- RAM might have an entry like-
/dev/ram0
- SD card partitions could be represented as:
/dev/mmcblk0p1 /dev/mmcblk0p2
- Serial devices could have entries like:
/dev/ttyS0 /dev/ttyS1 /dev/ttyO0
For example, a keyboard driver would create a file in /dev/ that enables applications to receive input from the keyboard. It is the driver’s task to ensure that the correct device files are created, making it possible for software to seamlessly interact with the hardware.
4. etc/
The /etc/ directory in a Unix/Linux system is crucial for storing system-wide configuration files and scripts used to manage the system’s startup, networking, and services. Here’s a more detailed breakdown of its contents:
Run-Level Scripts
This directory contains scripts that are used during different system run levels. Run levels define the state of the system, such as whether it’s running in a multi-user mode or in single-user mode. These scripts are executed automatically when the system enters a particular run level, helping to configure services like networking or multi-user access.
Start-Up and Shutdown Scripts
The /etc/ directory also holds scripts that control the system’s startup and shutdown processes. These scripts initialize or terminate various services when the system boots up or shuts down. They are essential for ensuring that the system starts with the necessary services running and shuts down gracefully.
Service Management Scripts
Scripts related to system services, such as starting or stopping networking, file sharing services like NFS (Network File System), and other background services, are stored here. These scripts make it possible to manually start or stop these services as needed, giving administrators control over the system’s behavior.
System Configuration Files
The /etc/ directory contains important configuration files that define system parameters. For example:
- The passwd file stores user account information, including usernames and encrypted passwords.
- The hostinfo file contains system-related details like the hostname and network settings. These files are critical for the system’s operation and are often used by various system utilities to configure or retrieve information.
Network Configuration Files: In this directory, you will also find configuration files related to networking, including settings for network interfaces, DNS, and routing. These files allow administrators to configure how the system communicates over a network, such as defining static IP addresses or configuring DHCP.
5. lib/
This directory contains:
- Dynamically loadable kernel modules.
- Essential shared libraries (.so.*) for dynamic linking.
Examples: C shared library (libc), math library, Python library, etc.
6. media/
This directory is primarily intended for mounting removable or external media devices. Examples include USB flash drives, SD cards, CD-ROMs, DVD drives, or any external storage device.
These devices are typically automatically mounted by the system when they are inserted or connected, and they are usually mounted under subdirectories within /media/ (ex- /media/usbdrive or /media/cdrom).
/media/ is intended for devices that are frequently plugged in and out of the system, making it more suitable for user-accessible storage devices.
- Example – When you plug a Pendrive, SD card, or other external storage, it is automatically mounted under /media/.
7. mnt/
This directory is generally used for temporarily mounting filesystems for tasks such as system maintenance or file transfers.
It is usually manually mounted by the system administrator (using the mount command) rather than automatically by the system.
The /mnt/ directory is typically used for mounting additional storage devices or network filesystems temporarily, such as during troubleshooting or data transfers. It’s a more flexible mount point that is not intended for regular user-accessible devices.
- Example – Mounting a network drive or remote filesystem for access during file transfers.
8. opt/
“Optional” directory used to install additional software packages. For example, running apt-get install <package> installs the package in this directory.
9. sbin/
The sbin/ directory contains commands related to system administration, which are used by system administrators for tasks like networking configurations, repairing, restoring, and recovering systems.
It is speculated that “sbin” stands for “System Admin’s bin.”
These commands are typically root-only and require elevated privileges to execute.
Here are some commands you might find in sbin/:
Command Description fastboot Reboot the system without checking the disks fasthalt Stop the system without checking the disks (optional) fdisk Partition table manipulator (optional) fsck File system check and repair utility (optional) fsck.* File system check and repair utility for a specific file system (optional) getty The getty program (optional) halt Command to stop the system (optional) ifconfig Configure a network interface (optional) init Initial process (optional) mkfs Command to build a file system (optional) mkfs.* Command to build a specific file system (optional) mkswap Command to set up a swap area (optional) reboot Command to reboot the system (optional) route IP routing table utility (optional) swapon Enable paging and swapping (optional) swapoff Disable paging and swapping (optional) update Daemon to periodically flush file system buffers (optional)
10. home/
Contains personal directories for each user.
Examples:
- Single-user mode: /home/developer
- Multi-user mode: /home/linux-user-1, /home/linux-user-2, /home/linux-user-3
11. srv/
The /srv/ directory stands for “Service” and is used to store data related to services provided by the system.
For example, if you are running an Apache web server, you would typically store your website files in a subdirectory like /srv/www/. Similarly, data for other services such as file servers, database servers, or FTP servers would be stored in /srv/ (e.g., /srv/nfs/ for NFS data). This directory helps keep service-related data organized and separate from other system files, making it easier to manage and configure services on the system.
12. tmp/
Applications store temporary files in this directory.
13. usr/
The /usr/ directory is part of the secondary hierarchy in the Filesystem Hierarchy Standard (FHS), and it contains system-wide read-only data, including software programs, libraries, and configuration files. It is primarily used for user and system programs that are not needed for basic system functionality but are essential for day-to-day operation.
Here are the key subdirectories of /usr/ and their purposes-
- /usr/bin/ : Contains most of the user commands, including binary executables for user-installed applications. For example, programs like Firefox or the zip command are found here because they are related to user-installed software, not essential system commands.
- /usr/include/ : Stores header files that are used in C and C++ programming. These files define function prototypes, constants, and other data structures needed for program compilation.
- /usr/lib/ : Holds libraries required by programs in /usr/bin/ and /usr/sbin/ to execute. These include shared libraries, linker/loader files, and other supporting files.
- /usr/local/ : Reserved for local software installations. This directory is typically empty after the initial installation of the system and is used for software that is manually installed by the system administrator or user, keeping it separate from the system-managed software in /usr/.
- /usr/sbin/ : Contains system binaries that are used by system administrators for non-vital system maintenance tasks. These commands are not necessary for basic system functionality but are required for administrative tasks (e.g., network configuration, system management).
- /usr/share/ : Stores architecture-independent data. This includes documentation, icons, man pages, and other shared resources that are not specific to a particular hardware architecture.
14. var/
The /var/ directory in Unix/Linux systems is used to store variable data—files that are expected to change in size or content during system operation. These include files such as logs, databases, and mail spools. The directory name “var” stands for “variable”, reflecting its purpose for files that can change dynamically over time.
Here are the key subdirectories of /var/ and their purposes-
- /var/log/ : Contains log files for system events, applications, and services. These logs are continuously updated by various programs and processes. For example, /var/log/syslog stores system logs, while /var/log/apache2/ stores logs related to the Apache web server.
- /var/spool/ : Holds spool files for tasks such as print jobs, mail queues, and cron jobs. For instance, /var/spool/mail/ stores incoming mail, and /var/spool/cron/ contains scheduled cron jobs for execution.
- /var/cache/ : Stores cached data that is used by applications to speed up future access. This can include data such as temporary files or downloaded package files. For example, package managers like apt use /var/cache/apt/ to store downloaded packages.
- /var/lib/ : Contains state information for system services and applications. This includes information required for the operation of databases, application data, and configuration states. For example, /var/lib/mysql/ stores MySQL database files.
- /var/tmp/ : Used for temporary files that need to persist across reboots. Unlike /tmp/, which is often cleared upon reboot, files in /var/tmp/ are meant to last longer and are used by programs that require temporary storage with a longer lifespan.
- /var/run/ : Stores runtime variable data such as process IDs (PIDs), lock files, and other information about the current running system state. For example, /var/run/utmp/ stores login session information.
- /var/mail/ : Contains user mailboxes, storing incoming and outgoing mail files for users on the system.
- /var/www/ : Used by web servers to store website content. For example, Apache typically stores website files in /var/www/html/, where web pages and associated files are served to clients.
So, here is some basic understanding of Linux device tree and file system structure.
I hope you will understand I used some basic understanding of it.
If you find any difficulty to understand any of the points you can send me a direct message or feel free to discuss it in comments.