Unix / Linux - File System Basics

Hello there, aspiring Unix/Linux enthusiasts! Welcome to our journey through the fascinating world of file systems. As your guide with years of teaching experience, I'm excited to help you understand these concepts, even if you're completely new to programming. Let's dive in!

Unix / Linux - File System Basics

Directory Structure

The Unix/Linux file system is organized like a tree, with the root directory (/) at the top. This structure is crucial for organizing and accessing your files efficiently.

Here's a simplified view of a typical Unix/Linux directory structure:

/
├── bin
├── etc
├── home
│   └── user
├── usr
└── var

Each of these directories serves a specific purpose:

  • /bin: Contains essential system binaries (executable programs)
  • /etc: Stores system configuration files
  • /home: Houses user home directories
  • /usr: Holds user programs and data
  • /var: Contains variable data like logs and temporary files

Key Directories and Their Functions

Directory Function
/bin Essential system binaries
/etc System configuration files
/home User home directories
/usr User programs and data
/var Variable data (logs, temp files)

Navigating the File System

Now that we understand the structure, let's learn how to move around. Think of it like exploring a new city - you need to know how to read the map and find your way!

Basic Navigation Commands

  1. pwd (Print Working Directory)

    $ pwd
    /home/user

    This command tells you where you are in the file system. It's like checking your current location on a map.

  2. ls (List)

    $ ls
    Documents  Downloads  Pictures  Music

    This command shows you what's in your current directory. It's like looking around to see what's near you.

  3. cd (Change Directory)

    $ cd Documents
    $ pwd
    /home/user/Documents

    This command lets you move to a different directory. It's like walking to a new location in our city analogy.

Remember, practice makes perfect! Try these commands out and get comfortable moving around your file system.

The df Command

The df command, short for "disk free," is your go-to tool for checking disk space usage. It's like checking how much room you have left in your closet!

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        20G   15G  4.0G  79% /
/dev/sdb1       100G   50G   50G  50% /home

The -h option makes the output human-readable. Here's what each column means:

  • Filesystem: The disk partition
  • Size: Total size of the partition
  • Used: Amount of space used
  • Avail: Available space
  • Use%: Percentage of space used
  • Mounted on: Mount point in the file system

The du Command

While df gives you an overview, du (disk usage) helps you dive deeper. It's like investigating which clothes are taking up the most space in your closet.

$ du -sh *
4.0K    Documents
2.0G    Downloads
500M    Pictures
1.5G    Music

The -s option gives a summary for each argument, and -h makes it human-readable.

Mounting the File System

Mounting is like plugging in a USB drive to your computer. It makes the file system accessible and usable.

To mount a file system:

$ sudo mount /dev/sdb1 /mnt/mydrive

This command mounts the device /dev/sdb1 to the directory /mnt/mydrive.

Unmounting the File System

Unmounting is the opposite of mounting. It's like safely ejecting a USB drive.

To unmount a file system:

$ sudo umount /mnt/mydrive

Always unmount before physically removing a drive to prevent data loss!

User and Group Quotas

Quotas are like setting a budget for disk space usage. They help prevent users from using too much space and affecting others.

To set a quota:

$ sudo edquota -u username

This opens an editor where you can set limits for the user.

To check quotas:

$ quota -v

This shows quota usage for the current user.

Quota Commands

Command Function
edquota Edit user quotas
quota Display disk usage and limits
repquota Report on quotas for a file system

And there you have it! We've covered the basics of the Unix/Linux file system. Remember, the best way to learn is by doing. So fire up your terminal and start exploring. Don't be afraid to make mistakes - that's how we learn!

As we wrap up, I'm reminded of a student who once said learning the file system was like learning to ride a bike - it seems daunting at first, but once you get the hang of it, you'll wonder how you ever managed without it.

Keep practicing, stay curious, and happy computing!

Credits: Image by storyset