DEV Community

Yusuf Isah
Yusuf Isah

Posted on • Originally published at yuscode.hashnode.dev

Chapter 3 - Linux File System

Image description

Introduction

The Linux file system is a crucial component of the operating system, organizing files and directories in a hierarchical structure. Understanding the file system hierarchy and how to navigate through it is essential for effective system management. This chapter will cover the file system hierarchy, path navigation, and file types.

Table of Contents

File System Hierarchy

The Linux file system hierarchy follows a tree-like structure with the root directory at the top. Here are some important directories and their purposes:

/ (Root)

The root directory is the topmost directory in the Linux file system hierarchy. All other directories and files are located under this directory.

/bin

Contains essential binary executables required for system booting and single-user mode operation. Common commands like ls, cp, and mv are located here.

/etc

Holds system configuration files and scripts. For example, passwd (user account information) and fstab (file system mount information) are found here.

/home

Contains the home directories for all users. Each user has a subdirectory under /home where their personal files and settings are stored.

/var

Stores variable data files such as logs, databases, and email. For example, system logs are located in /var/log.

/tmp

A temporary directory where programs can store temporary files. These files are typically cleared upon system reboot.

/usr

Holds user applications and utilities. It includes subdirectories like /usr/bin for user binaries and /usr/lib for libraries.

Path Navigation

Navigating the Linux file system efficiently is key to managing files and directories. Here are the basics of path navigation:

Absolute Paths

Absolute paths start from the root directory and specify the complete path to a file or directory. An example is shown below:

cd /home/user/documents
Enter fullscreen mode Exit fullscreen mode

Relative Paths

Relative paths start from the current directory and do not begin with /\. Examples are shown below:

cd documents/reports
Enter fullscreen mode Exit fullscreen mode
  • mv ./file.txt ../../dir/: This command moves the file file.txt from the current directory to the dir directory located two levels up. The dot . before / in ./file.txt means the current directory.

    mv ./file.txt ../../dir/
    
  • cp ../../dir/file.txt ./: This command will copy the file file.txt from the dir directory located two levels up to the current directory. ./ refers to the current directory.

    cp ../../dir/file.txt ./
    

Special Directories

  • . Represents the current directory.

  • .. Represents the parent directory.

  • ~ Represents the home directory of the current user.

File Types

Understanding different file types in Linux is essential for managing the file system effectively.

  • Regular Files: Regular files contain data, text, or program instructions. They can be created using commands like touch or text editors like nano and vim. We'll cover text editors in another chapter of this series.

  • Directories: Directories are special types of files that contain other files and directories. They are created using the mkdir command.

  • Symbolic Links: Symbolic links are special files that point to other files or directories. They are created using the ln -s command.

    ln -s /path/to/original /path/to/link
    

Another example is shown below:

```sh
ln -s /home/user/documents/file.txt /home/user/Desktop/file_link
```
Enter fullscreen mode Exit fullscreen mode

The Linux command above creates a symbolic link called file_link on the Desktop, which points to the original file file.txt in the documents directory. When you access the symbolic link file_link, you'll actually be accessing the original file file.txt in the documents directory. If you edit the symbolic link, you'll be editing the original file!

Conclusion

Understanding the Linux file system hierarchy, path navigation, and file types is fundamental to effectively managing a Linux system. These concepts form the basis of file management and system organization, enabling you to perform various administrative tasks efficiently.

Feel free to leave comments and share this article. Follow my blog for more insights on Linux!

Top comments (0)