DEV Community

Harsh Pandhe
Harsh Pandhe

Posted on • Edited on

3 1 1 1 1

Day 03: The Linux File System

Welcome to Day 3 of our Linux series! Yesterday, we became command-line ninjas, learning the essentials of navigating and managing files. Today, we’ll explore the Linux file system—an organized chaos of directories that make Linux both powerful and efficient. Ready? Let’s decode this mystery together!

Linux file System


Understanding the Linux File System

The Linux file system is like a tree. The root (/) is the base, and everything branches out from there. Unlike Windows, Linux doesn’t have drive letters (C:\, D:). Instead, all files and directories are part of this single tree structure.


Key Directories in Linux

Let’s take a tour of the Linux file system—a virtual sightseeing trip through the most important directories:

1. / (Root Directory)

  • The starting point of the Linux file system.
  • All other directories live here.
  • Warning: Messing around here without caution can lead to disaster. Treat it like it’s a beehive—observe, but don’t poke!

2. /home

  • Home sweet home! Each user has their personal space here (e.g., /home/username).
    Home Sweet Home

  • This is where you’ll spend most of your time, storing personal files and configurations.

3. /bin

  • Short for “Binaries”—contains essential programs and commands, like ls, cp, and mv.
  • These are the tools you’ve been using from Day 2!

4. /usr

  • Short for “User” resources. Think of it as the treasure chest of user applications and libraries.
  • Contains directories like /usr/bin for user-installed programs and /usr/share for shared files.

User

5. /etc

  • The configuration headquarters of Linux.
  • Contains system-wide settings for programs and services (like /etc/hostname for the system’s name).

6. /var

  • Stores variable files like logs, databases, and emails.
  • Example: Check system logs in /var/log to troubleshoot problems. variable

7. /tmp

  • Temporary storage. Files here are automatically deleted after a reboot.
  • Useful for storing short-lived data.

8. /dev

  • Stands for “Devices.” Contains files that represent hardware devices (e.g., /dev/sda for your hard drive). Devices

9. /proc and /sys

  • Virtual filesystems providing information about system processes and hardware.
  • Example: Check CPU info with:
  cat /proc/cpuinfo
Enter fullscreen mode Exit fullscreen mode

Navigating the Linux File System

Absolute vs. Relative Paths

  • Absolute Path: Starts from the root directory (/). Example: /home/user/Documents.
  • Relative Path: Starts from your current directory. Example: Documents (if you’re already in /home/user).

Common Navigation Commands

  • pwd: Print your current location. pwd
  • ls: List files in a directory.
  • cd: Change directories.

    • Example: Move to /var/log:
    cd /var/log
    

Working with Files and Directories

Create a Directory

mkdir <directory_name>
Enter fullscreen mode Exit fullscreen mode
  • Example:
  mkdir Projects
Enter fullscreen mode Exit fullscreen mode

mkdir

Delete a Directory

rmdir <directory_name>
Enter fullscreen mode Exit fullscreen mode
  • Use rmdir for empty directories or rm -r for directories with content.
  • Example:
  rm -r Projects
Enter fullscreen mode Exit fullscreen mode

Check Disk Usage

du -h
Enter fullscreen mode Exit fullscreen mode
  • Shows disk usage in a human-readable format.
  • Example:
  du -h /home
Enter fullscreen mode Exit fullscreen mode

Check Available Disk Space

df -h
Enter fullscreen mode Exit fullscreen mode
  • Displays available disk space for each filesystem.

Tips for Navigating Like a Pro

Navigating Like a Pro

1. Use Tab for Auto-Completion

  • Press Tab while typing a file or directory name to auto-complete it. Double Tab shows options if there are multiple matches.

2. Hidden Files Start with a Dot

  • Files like .bashrc are hidden. Use ls -a to see them.

3. Use Aliases for Long Paths

  • Create shortcuts in your .bashrc file. Example:
  alias docs="cd /home/user/Documents"
Enter fullscreen mode Exit fullscreen mode

Fun Linux Fact

Linux doesn’t just run on computers. It’s in space! The International Space Station uses Linux to control systems and perform experiments. 🚀

ISS


Conclusion

Congratulations! You’ve just uncovered the secrets of the Linux file system. By now, you should feel more confident navigating and working with directories. Keep exploring and practicing these commands to master the Linux filesystem.

What’s Coming Next?

Tomorrow, we’ll dive into Shell Scripting Basics and learn how to automate tasks like a pro. See you for Day 4 of this series!

Top comments (2)

Collapse
 
lavkushsingh34 profile image
Lavkush_Singh

Thank you for this awesome Linux series. Very very helpful. Again thank you 🤩🤩🤩

Collapse
 
harshpandhe profile image
Harsh Pandhe

Hi Lavkush! 😊 Thank you so much for your kind words! I’m really glad to hear that you’re finding the Linux series helpful. It means a lot to know that it’s making a difference for you. If you have any questions or topics you’d like me to cover next, feel free to let me know! Happy coding! 🤓🚀

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series