Chapter 3: Navigation and File Systems
In Unix-like systems, "everything is a file." Whether it's your hard drive, your keyboard, or a simple text document, the shell interacts with them all through the file system hierarchy. Mastering navigation is about understanding the Filesystem Hierarchy Standard (FHS) and how to control access through permissions.
I. The Unix Directory Structure
Unlike Windows, where every drive has its own root (like C:\ or D:\), Unix systems have a single unified root (/). All storage devices are "mounted" as folders within this tree.
Key Directories to Know:
/bin&/usr/bin: Essential command binaries (likels,cp)./etc: System-wide configuration files (e.g., password files, network config)./home: Personal directories for regular users./root: The home directory for the superuser (Administrator)./tmp: Temporary files (often cleared on reboot)./dev: Hardware devices represented as files (e.g.,/dev/sdafor a disk).
II. File Permissions (rwx)
Unix security is based on three types of access for three types of people.
| Permission | For a File | For a Directory |
|---|---|---|
| Read (r) | View the contents. | List the files inside. |
| Write (w) | Modify the contents. | Add or delete files inside. |
| Execute (x) | Run as a program. | Enter the directory (cd). |
The ls -l Breakdown
When you run ls -l, you see a string like -rwxr-xr--.
-: File type (-for file,dfor directory).rwx: Owner permissions.r-x: Group permissions.r--: Others (everyone else).
III. Modifying Permissions and Ownership
chmod (Change Mode)
You can use symbolic or numeric notation to change permissions.
- Symbolic:
chmod u+x script.sh(Add execute for user). - Numeric:
chmod 755 script.sh(Owner: rwx, Group: r-x, Others: r-x).- Read = 4, Write = 2, Execute = 1. (4+2+1=7).
chown (Change Owner)
Requires administrative privileges (sudo).
sudo chown jane:developers report.txt
# Changes owner to 'jane' and group to 'developers'
IV. Finding Files
As the filesystem grows, you need powerful tools to find data.
find (The Powerhouse)
Searches the directory tree based on attributes.
find /home -name "*.pdf" -size +10M
# Finds all PDFs larger than 10MB in /home
locate (The Speedster)
Uses a pre-built database for near-instant results.
locate config.yaml
V. Disk Usage Analysis
du(Disk Usage): How much space is this folder taking?du -sh .(Show summary of current folder in human-readable format).
df(Disk Free): How much space is left on my hard drives?df -h.
In the next chapter, we'll learn how to customize our environment using Variables and Dotfiles.