Fundamentals

Linux Filesystem & Shell

What Bash actually is, how files and directories work, the Linux filesystem structure, the root directory, the root user, switching users with su, and mastering the ls command family.

6 sections

filesystem essentials

~25 min

estimated reading

Beginner

no prerequisites

What is Bash?

Bash stands for Bourne Again Shell. It's the language your terminal speaks. When you type commands in the terminal, Bash is the program that reads, understands, and executes them.

Why is Bash Used in the Terminal?

Three simple reasons make Bash the go-to shell for Linux:

1

It's the default on most Linux systems

When you open a terminal on Ubuntu or most Linux distros, Bash is already running. It's been the standard since 1989. You don't need to install anything — it's just there, ready to go.

2

It can run commands AND write scripts

Bash works in two ways: Interactive mode (you type commands one by one and get instant results — like a live conversation) and Script mode (you write multiple commands in a .sh file and run them all at once — like writing instructions). That's exactly why script files start with #!/usr/bin/env bash — it tells the system 'use Bash to read this file.'

3

It's powerful but simple

You can do everything with Bash — navigate folders, create files, manage users, install software, automate tasks, manage servers. All with short, simple commands.

Are There Other Shells?

Yes! Bash is just one shell. There are others, each with slightly different features:

Common Terminal Shells

ShellFull NameNotable For
bashBourne Again ShellDefault on most Linux systems since 1989
zshZ ShellDefault on macOS. More features, better autocomplete
shBourne ShellThe original — very basic, maximum compatibility
fishFriendly Interactive ShellBeginner-friendly, colorful, smart suggestions
🗣️
Think of it this way...

Think of shells like different languages. English (Bash), Spanish (zsh), French (fish) — they all let you communicate with the operating system, but they have different accents and features. When you write a script, you choose which language (shell) to use at the top of the file with #!/usr/bin/env bash.

💡

Key Takeaway

Bash is the language your Linux terminal speaks. It's been the default since 1989, works both interactively (type commands) and as a scripting language (run .sh files). Other shells like zsh and fish exist, but Bash is still the most universal.

Files, Directories & the Filesystem

Three terms that look similar but mean very different things: a file is a piece of data, a directory is a folder that organizes files, and a filesystem is the entire system that makes both possible.

The File

A file is a single piece of data stored on disk. It could be anything:

Examples of files
report.txt           ← a text file
photo.jpg            ← an image
filesystem-report.sh ← a script
data.csv             ← a spreadsheet
notes.pdf            ← a PDF document

Every file has: a name, contents (the actual data inside), and metadata (owner, permissions, size, date modified). Think of it as a single document in a filing cabinet.

The Directory

A directory is a folder that holds files (and other directories inside it). It doesn't contain data itself — it just organizes files.

Directory structure example
/home/charith/
├── projects/           ← directory
│   ├── app.py          ← file
│   └── README.md       ← file
├── notes/              ← directory
│   └── todo.txt        ← file
└── .bashrc             ← file (hidden — starts with .)

Think of a directory as a folder in a filing cabinet. The folder itself isn't a document — it just groups documents together.

The Filesystem

A filesystem is the entire system that manages how files and directories are stored on a disk. It's the structure and rules that make files and directories possible.

🏙️
Think of it this way...

If files are individual documents and directories are folders, the filesystem is the entire filing room — with its cabinets, the organization system, the rules for naming things, and the physical shelves everything sits on. Without the filesystem, your disk is just raw 1s and 0s with no meaning.

📄

File

A single piece of data. Has a name, contents, and metadata (size, owner, date).

notes.txt, photo.jpg, script.sh
📁

Directory

A folder that organizes files and other directories. Contains no data itself.

/home/charith/, /projects/, .ssh/
💽

Filesystem

The entire system that manages storage. Rules for how 1s and 0s become files you can open.

ext4 (Linux), APFS (macOS), NTFS (Windows)
💡

Key Takeaway

File = a piece of data. Directory = a folder that organizes files. Filesystem = the entire system of rules and structure that makes files and directories possible on disk. Without a filesystem, your storage is just meaningless 1s and 0s.

The Linux Filesystem Structure

In Linux, every single file and folder lives under one starting point called the root directory, written as /. This is completely different from Windows, where you have separate drives like C:\ and D:\.

What Does / Mean?

In Linux, / is the starting point of everything. Every single file and folder on your system lives under it:

Linux filesystem tree
/ (root directory — EVERYTHING starts here)
├── home/        (your personal files)
│   └── charith/ (your home folder)
│       ├── projects/
│       └── notes.txt
├── etc/         (system settings)
│   └── passwd   (user accounts list)
├── var/         (logs, data)
│   └── log/
│       └── syslog
├── usr/         (programs and utilities)
├── tmp/         (temporary files)
└── ... literally everything else
🏠/home

Personal files for each user. Your stuff lives here.

⚙️/etc

System configuration files. Settings for every service.

📊/var

Variable data — logs, databases, spool files.

🔧/usr

Programs and utilities installed on the system.

🗑️/tmp

Temporary files. Cleared on reboot.

/bin

Essential commands: ls, cp, mv, bash etc.

🌳
Think of it this way...

Think of the Linux filesystem as an upside-down tree. The root / is the trunk at the very top. Branches grow downward — /home, /etc, /var. Each branch can have more branches (subdirectories). Files are the leaves at the ends. Everything connects back to the same trunk: /.

Linux vs Windows Filesystem Comparison

FeatureLinuxWindows
Starting point/ (one root for everything)C:\ D:\ E:\ (separate drives)
Path separator/ (forward slash)\ (backslash)
Home folder/home/charithC:\Users\Charith
Config files/etc/C:\Windows\System32\
Case sensitive?Yes — file.txt ≠ File.txtNo — same file
💡

Key Takeaway

In Linux, everything lives under / — a single root that branches into /home, /etc, /var, etc. Unlike Windows with separate drives (C:\\, D:\\), Linux has one unified tree. Every path starts from /.

The Root User

Don't confuse the root directory (/) with the root user. They share a name but are completely different things. The root user is the most powerful user on a Linux system — it can do absolutely anything.

⚠️

Warning

The root user can do everything — including break the entire system. That's why you should never log in as root for daily work. Instead, use sudo for individual commands that need admin permissions. This limits damage if you make a mistake.

root vs Regular User

Regular User vs Root

ActionRegular UserRoot User
Install software❌ Needs sudo✅ Always
Delete system files❌ Permission denied✅ No restriction
View any file❌ Some files restricted✅ All files
Change passwordsOnly their ownAnyone's
Break the systemHard to do accidentallyOne wrong command can do it
Promptcharith@ubuntu:~$root@ubuntu:~#

How to Tell Who You Are

Checking who you are
▶️

Click the Play button above to start!

Watch the commands execute step by step

🤯

Did You Know?

The # symbol in the shell prompt is a universal warning sign — it means you are root. When you see # instead of $, be extra careful. Every command runs with unrestricted power.

💡

Key Takeaway

The root user (username: root) has absolute power on Linux — can do anything, including accidentally destroy the system. Never work as root for regular tasks. Use sudo for individual commands that need admin rights. When your prompt shows # instead of $, you are root — be careful.

Switching Users with su

su stands for Switch User. It lets you change to a different user account in the terminal without logging out. The difference between su username and su - username is subtle but important.

The Command

Switching to another user
▶️

Click the Play button above to start!

Watch the commands execute step by step

With - vs Without -

su testdev

Without -

Switches to testdev but stays in your current folder with your settings. You're the person but in the wrong house.

su - testdev

With - ✅ Recommended

Switches to testdev AND takes you to their home folder with their settings loaded. Fully becomes that user.

🏠
Think of it this way...

Imagine visiting someone else's apartment. su testdev = You walk into their apartment but bring your own furniture and stuff — kind of weird. su - testdev = You walk in and use everything as they set it up — their desk, their settings, their environment. Like actually becoming them. Always use - for a clean, proper switch.

💡

Key Takeaway

su switches your user identity in the terminal. Always use su - (with a dash) to get the full environment of the target user — their home folder, settings, and PATH. Without the dash, you switch identity but keep your current context, which causes confusing behavior.

Mastering ls

ls is the most used command in Linux. It lists the contents of a directory. But the real power comes from its flags — -l, -a, and combining them. And Ubuntu even gives you a shortcut: ll.

The Four Variations

ls command family
▶️

Click the Play button above to start!

Watch the commands execute step by step

Reading the ls -l Output

That long output from ls -l looks confusing at first. Let's decode it:

-rwxr-xr-- 1 charith charith 1024 Feb 18 10:30 notes.txt

ls -l output decoded

PartWhat It Means
-rwxr-xr--Permissions (who can read, write, execute) — more on this in File Permissions
1Number of hard links to this file
charith (first)Owner of the file
charith (second)Group of the file
1024File size in bytes
Feb 18 10:30Last modified date and time
notes.txtThe filename

Hidden Files — What the -a Flag Reveals

In Linux, any file or folder starting with a . (dot) is hidden. Regular ls won't show them. You need ls -a or ls -la:

.bashrc

Your shell configuration — customizations, aliases, etc.

.ssh/

SSH keys and config — kept hidden for security

.profile

Runs at login — sets environment variables

The ll Shortcut

Ubuntu comes with a pre-made alias — a shortcut for a longer command. ll is just a shorter way to type ls -la:

ll=ls -laThey do the exact same thing

Because typing ls -la many times a day gets tiring, Ubuntu includes this alias by default. It's defined in your ~/.bashrc file.

Quick ls Reference

CommandWhat It Shows
lsFile names only (no hidden files, no details)
ls -lFile names with full details (permissions, owner, size, date)
ls -aAll files including hidden (dot files), names only
ls -laAll files including hidden, with full details
llSame as ls -la (Ubuntu alias — shorter to type)
💡

Key Takeaway

ls lists files. ls -l adds details. ls -a reveals hidden dot files. ls -la (or ll) does both — the most informative view. Use ll in Ubuntu for the full picture with minimal typing.

Linux Filesystem Quiz

1 / 6

What does Bash stand for?

Filesystem Flashcards

Click any card to flip and reveal the definition.

What is Bash?

Bourne Again Shell — the language your terminal speaks. When you type commands, Bash is the program that understands and executes them. It's the default shell on most Linux systems since 1989.

What is a shell?

A shell is a program that lets you interact with the operating system through text commands. Bash is one shell. Others include zsh (macOS default), fish, and sh. They all do the same basic job but with different features.

What is a file?

A single piece of data stored on disk. It has a name, contents (the actual data), and metadata (owner, permissions, size, date modified). Like a single document in a filing cabinet.

What is a directory?

A folder that holds files and other directories. It doesn't contain data itself — it just organizes files. Like a folder in a filing cabinet that groups documents together.

What is a filesystem?

The entire system that manages how files and directories are stored on a disk. It's the structure and rules (like ext4 on Linux) that make files and directories possible. Without it, your disk is just raw 1s and 0s.

What is / in Linux?

The root directory — the very top of the filesystem. Every file and folder on Linux lives somewhere under /. It's where everything begins. /home, /etc, /var, /usr all live under /.

What is the root user?

The most powerful user on a Linux system. Username is literally 'root'. Can do absolutely anything — install software, delete files, change settings, add/remove users, even break the system.

What does 'su - username' do?

Switch User — changes to another user account with their full environment (home folder, settings, etc.). The '-' flag loads their full environment. Without '-', you switch but keep your current folder and settings.

What does 'ls -la' show?

Lists ALL files (including hidden dot files) with full details: permissions, number of links, owner, group, file size, date modified, and filename. The most informative way to view directory contents.

What are hidden files in Linux?

Files starting with a dot (.) are hidden. For example: .bashrc, .ssh/, .profile. They don't show in a regular 'ls' command — you need 'ls -a' or 'ls -la' to see them.