Day-2b: Linux File Hierarchy Structure

Day-2b: Linux File Hierarchy Structure

A “Tree” in Linux creates a list of files and folders in a way that looks like a tree with branches. If you run it without any extra instructions/options, it shows all the files and folders in the current place in which you are working. If you tell it which folder to look into, it will list the files and folders inside those places. At the end, it counts how many folders and folders it found and shows the total. You can also change how the list looks like by adding colors or using different symbols to make it easier to read.

To Install Tree, first you need to update the Linux with command:

yum update -y

and than you can install the tree with command: yum install tree

In order to see if tree is install, you can use following 2 commands:

tree --version

tree

About File Hierarchy

Linux, like other UNIX-based systems, organizes files in a tree-like structure.

  • In this structure, "parent" directories can have "child" directories or files inside them.

  • Files are like the "leaves" of the tree, while directories can branch out to include other directories.

  • You can find any file or directory by its "path name."

  • An absolute path name starts with a / (the root directory that contains everything) and lists all the directories you need to go through to reach the file or directory, with each directory separated by a /.

The Types Of Files

  • /

  • /bin

  • /dev

  • /etc

  • /home

  • /lib

  • /media

  • /mnt

  • /opt

  • /proc

  • /root

  • /sbin

  • /srv

  • /sys

  • /tmp

  • /usr

  • /var

You can see the list of all Files and folders with command:

ls

ls-l

Features

  • /

    This is the home directory of root user.

  • /bin:

    This is location for most popular commands which we use in terminal on daily basis. Commands like ls, mount, rm etc. which we use on daily basis are stored in this location.

  • /dev

    The /dev directory in Linux is a special filesystem that contains device files, which are interfaces to hardware or virtual devices. These files allow the system and users to interact with devices like disks, USBs, printers, and pseudo-devices (e.g., /dev/null or /dev/random) as if they were regular files.

    For example:

    • /dev/sda: Represents the first hard drive.

    • /dev/tty: Represents terminals.

    • /dev/null: A "black hole" where data is discarded.

The /dev directory is managed by udev, a device manager that dynamically creates and removes device files as hardware is added or removed.

  • /etc

    The /etc directory in Linux contains the configuration files for the system and this is a critical directory where most of the system related settings and configurations are stored.

    Common Files and Subdirectories:

    • /etc/passwd: Contains user account information.

    • /etc/fstab: Defines filesystems to be mounted at boot.

    • /etc/hosts: Maps hostnames to IP addresses.

    • /etc/network/: Contains network configuration files.

    • /etc/ssh/: Configuration for SSH services.

Important Note:

Modifying files in /etc requires administrative privileges (e.g., sudo) and should be done with caution to avoid misconfiguring the system.

  • /home

    The /home directory in Linux is where user-specific data and configuration files are stored. Each user on the system typically has a subdirectory within /home named after their username.

  • /proc

    The /proc directory in Linux is a virtual filesystem that provides information about the system and running processes. It doesn’t contain real files; instead, it dynamically generates files and directories to represent kernel and process data.

  • /sys

    The /sys directory in Linux is a virtual filesystem (like /proc) that provides a way to interact with and retrieve information about hardware devices and their drivers. It is also referred to as sysfs and is managed by the kernel.

    Key Directories:

    • /sys/devices: Contains all devices connected to the system, organized by their physical hierarchy.

    • /sys/class: Groups devices by their type or class (e.g., network, block).

    • /sys/block: Represents block devices like hard drives and partitions.

    • /sys/bus: Contains details about buses (e.g., PCI, USB) used by devices.

    • /sys/kernel: Provides kernel-related settings and information.

    • /sys/module: Displays information about loaded kernel modules.

  • /tmp

    The /tmp directory is a temporary storage location in Linux that serves as a place for programs to store temporary files they need while running. If you are not sure, don’t remove/delete temporary file since it will result in crashing the system as it might be crucial for the program.

  • /usr

    This includes most of the user utilities and programme and partially mimics the root directory structure, including, among other things, /usr/bin and /usr/lib.

  • /var

    The /var directory in Linux is used to store variable data that changes frequently during the system's operation. This includes files that are updated regularly, such as log files, spool files, cache files, and temporary files created by applications. Think of /var as your computer's "diary" or "log book".

  • /lib

    This includes crucial kernel modules and dynamic libraries.

  • /boot

    Think of /boot as your computer's "starter kit" - it contains all the essential files needed to start (boot) your computer. It's like the ignition system of a car. It stores the bootloader, the kernel, and other files required to initiate the operating system startup process.

I hope you enjoy reading the Blog and if you like, do reshare with the community !!

##