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:
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.
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.'
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
| Shell | Full Name | Notable For |
|---|---|---|
| bash | Bourne Again Shell | Default on most Linux systems since 1989 |
| zsh | Z Shell | Default on macOS. More features, better autocomplete |
| sh | Bourne Shell | The original — very basic, maximum compatibility |
| fish | Friendly Interactive Shell | Beginner-friendly, colorful, smart suggestions |
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:
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.
/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.
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.shDirectory
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:
/ (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
/homePersonal files for each user. Your stuff lives here.
/etcSystem configuration files. Settings for every service.
/varVariable data — logs, databases, spool files.
/usrPrograms and utilities installed on the system.
/tmpTemporary files. Cleared on reboot.
/binEssential commands: ls, cp, mv, bash etc.
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
| Feature | Linux | Windows |
|---|---|---|
| Starting point | / (one root for everything) | C:\ D:\ E:\ (separate drives) |
| Path separator | / (forward slash) | \ (backslash) |
| Home folder | /home/charith | C:\Users\Charith |
| Config files | /etc/ | C:\Windows\System32\ |
| Case sensitive? | Yes — file.txt ≠ File.txt | No — 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
| Action | Regular User | Root User |
|---|---|---|
| Install software | ❌ Needs sudo | ✅ Always |
| Delete system files | ❌ Permission denied | ✅ No restriction |
| View any file | ❌ Some files restricted | ✅ All files |
| Change passwords | Only their own | Anyone's |
| Break the system | Hard to do accidentally | One wrong command can do it |
| Prompt | charith@ubuntu:~$ | root@ubuntu:~# |
How to Tell 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
Click the Play button above to start!
Watch the commands execute step by step
With - vs Without -
su testdevWithout -
Switches to testdev but stays in your current folder with your settings. You're the person but in the wrong house.
su - testdevWith - ✅ Recommended
Switches to testdev AND takes you to their home folder with their settings loaded. Fully becomes that user.
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
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.txtls -l output decoded
| Part | What It Means |
|---|---|
| -rwxr-xr-- | Permissions (who can read, write, execute) — more on this in File Permissions |
| 1 | Number of hard links to this file |
| charith (first) | Owner of the file |
| charith (second) | Group of the file |
| 1024 | File size in bytes |
| Feb 18 10:30 | Last modified date and time |
| notes.txt | The 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:
.bashrcYour shell configuration — customizations, aliases, etc.
.ssh/SSH keys and config — kept hidden for security
.profileRuns 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 thingBecause 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
| Command | What It Shows |
|---|---|
| ls | File names only (no hidden files, no details) |
| ls -l | File names with full details (permissions, owner, size, date) |
| ls -a | All files including hidden (dot files), names only |
| ls -la | All files including hidden, with full details |
| ll | Same 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
What does Bash stand for?
Filesystem Flashcards
Click any card to flip and reveal the definition.