A Detailed Guide to Basic Linux Concepts

g57e4bf95745e82df2c5e0ec605e8f81b12ba359e98bc5d602551cb18c473f21f9fcd4533f56eaf3ba1764bd1ed6bae22b5e12cae993b4f4aec83757f7f260d8b_1280-7207969.jpg

Linux is a powerful, open-source operating system that has become the foundation for a wide variety of devices, from personal computers to servers, smartphones, and embedded systems. In this blog, we’ll explore the fundamental concepts of Linux, its history, the file system hierarchy, and the critical concepts of permissions and ownership.

What is Linux?

Introduction to Linux

Linux is an open-source, Unix-like operating system kernel that was originally developed by Linus Torvalds in 1991. It was created as a free alternative to the proprietary Unix operating systems of the time. Over the years, Linux has grown into a mature and widely-used operating system with multiple distributions tailored for different purposes.

Linux itself is just the kernel, the core part of the operating system that interacts with hardware. However, what we commonly refer to as Linux in daily use is the kernel combined with GNU tools and libraries, resulting in a fully functional operating system.

The Importance of Linux

Linux powers:

  • Servers: A significant portion of the world’s servers, including cloud infrastructure (Amazon Web Services, Google Cloud, etc.), run on Linux.
  • Embedded Systems: Linux is widely used in embedded systems like routers, smart TVs, and industrial controllers.
  • Desktops and Laptops: Distributions like Ubuntu, Fedora, and Linux Mint offer user-friendly experiences for personal computers.
  • Mobile Devices: Android, the most popular mobile operating system, is based on the Linux kernel.

Linux Distributions (Distros)

A Linux distribution (distro) is a packaged version of Linux that includes the Linux kernel, GNU tools, libraries, desktop environments, and package management systems. Distros are often tailored for specific users. Here are some popular ones:

  • Ubuntu: A beginner-friendly distro with a string focus on ease of use and community support. It’s widely used on desktops and servers.
  • Debian: Known for its stability, Debian is the base for many other distributions, including Ubuntu.
  • Fedora: A cutting-edge distro that showcases the latest innovations in the Linux ecosystem.
  • CentOS: A stable, enterprise-level distribution often used in servers. It’s a free version of Red Hat Enterprise Linux (RHEL).
  • Arch Linux: A rolling-release distro designed for advanced users who want complete control over their system.

Linux Filesystems Hierarchy

The Linux filesystems hierarchy is the structure in which files and directories are organized. It follows a standard known as the Filesystem Hierarchy Standard(FHS), which defines the layout of directories and what type of files they should contain. Below are some of the most important directories you’ll encounter in any Linux distribution:

Root Directory /

The top-level directory in a Linux system is represented by /. All files and directories are nested under this root directory. Unlike Windows, where each drive (C: D:) is mounted separately, in Linux, all drives and partitions are mounted within the root directory.

Important Directories

  • /home: This directory contains the home directories for all user accounts. For example, if your username is john, your personal files and configurations would be stored in /home/john. Each user has a separate home directory, which ensures privacy and isolation.
  • /etc: This directory holds system-wide configuration files. Most configuration files are stored in plain text, making it easy to edit them using a text editor. For example, /etc/passwd holds user account infomation, while /etc/hosts is used for local hostname resolution.
  • /var: This directory contains variable data files, such as logs, databases, and emails. For instance, log files for system events are stored in /var/log/. The contents of this directory change frequently as system services run and create logs.
  • /bin: The /bin directory holds essential binary executable (programs) needed for the system to boot and function correctly, even in single-user mode. Commands like ls, cp, mv, and bash are found here.
  • /lib: This directory contains shared libraries needed by the binaries in /bin and /sbin. These libraries are similar to DLL fiels in Windows. For example, the core system libraries used by the kernel are found in /lib.
  • /sbin: The /sbin directory holds system binaries, typically used for administrative tasks. These include commands like shutdown, mount, ifconfig. These are primarily intended for use by the system administrator(root user).
  • /usr: This is one of the largest directories in most Linux installations and holds user-installed software and system utilities. Key subdirectories include:
    • /usr/bin: Contains the majority of the user-executable files.
    • /usr/sbin: Holds system administration binaries.
    • /usr/lib: Contains libraries used by programs in /usr/bin and /usr/sbin.
  • /dev: This directory contains device files that represent hardware devices like hard drives, USBs, and printers. For instance, /dev/sda might represent the first hard drive on your system, while /dev/tty might represent a terminal device.
  • /tmp: The /tmp directory is used for temporary files created by applications and the system. Files stored here are often deleted on reboot.
  • /proc: A virtual filesystem that contains information about running processes and the system state. For example, /proc/cpuinfo provides details about the system’s CPU, and /proc/meminfo offers memory-related information.

Permissions and Ownership

Linux is a multi-user system, which means multiple users can interact with the system at the same time. To ensure privacy and security, Linux employs a permissions and ownership model that governs who can read, write, or execute a file.

Understand rwx(read, write, execute) permission

Permissions in Linux are represented as a cmbination of three main actions:

  • Read(r) : Allows viewing the contents of a file or listing the contents of a directory.
  • Write(w): Allows modifying the contents of a file or creating/deleting files within a directory.
  • Execute(x): Allows executing a file as a program or entering a directory (cd)

Permissions are grouped into three categories:

  • Owner: The user who owns the file.
  • Groups: A group of users who share certain permissions.
  • Others: All other users who are neither the owner nor in the group.

The permissions are displayed using the ls -l command. For example:

-rwxr-xr--

This output can be interpreted as:

  • rwx: The owner can read, write, and execute.
  • r-x: The group can read and execute, but not write.
  • r–: Others can only read.

Changing Permissions with chmod

You can modify file permissions using the chmod command. There are two ways to represent permissions: symbolic mode and numeric mode.

  • Symbolic Mode: Modify specific permissions by adding/removing attributes.
    • chmod u+x file: Adds execute permission for the user(owner)
    • chmod g-w: Removes write permission for the group.
  • Numeric Mode: Use numbers to represent permission sets. The values are:
    • r = 4, w = 2, x = 1
    • so, chmod 755 file sets:
      • Owner: rwx(7)
      • Group: r-x(5)
      • Other: r-x(5)

Changing Ownership with chown

The chown command is used to change the owner and group of a file. For example:

  • chown john file: Changes the owner of the file to john.
  • chown john:staff file: Changes the owner to john and the gorup to staff

Conclusion

In this guide, we covered the essential concepts for anyone starting their Linux journey. You now have a basic understanding of what Linux is, how its filesystem is structured, and the critical permissions model that governs file access. Mastering these fundamentals is the first step towards becoming proficient in Linux, enabling you to explore more advanced topics such as system administration, scripting, and network management.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top