The Plain Picture#
You're walking around inside a huge building of nested rooms. At any moment you're standing in exactly one room. You can ask "where am I?", "what's in this room?", and "take me to that room".
The Real Names#
The room you're in is the current working directory.
pwd— print working directory: "where am I?"ls— list: "what's in here?"cd— change directory: "take me there."
Paths — absolute (/var/log) and relative (../logs) — are from Operating Systems Ch 10. Shortcuts:
| Symbol | Means |
|---|---|
/ | the root of the whole file system |
~ | your home directory (/Users/priya on a Mac; /home/priya on Linux) |
. | the current directory |
.. | the parent directory (one up) |
- | (with cd) the previous directory you were in |
Under the Hood#
pwd # /Users/priya
cd Documents/01_STUDY # relative path: from here, go into Documents, then 01_STUDY
ls # README.md 01_Basics/01_Foundations
ls -l # long format: permissions, owner, size, date
ls -la # also show hidden files (names starting with a dot, like .env)
ls -lh # human-readable sizes (4.2K, 18M) instead of bytes
cd .. # up one level → /Users/priya/Documents
cd ~ # home (plain `cd` does the same)
cd - # back to where you just wereReading ls -l (the columns are explained over the next chapters):
-rw-r--r-- 1 priya staff 2790 23 Aug 23:11 README.md └────┬───┘ └───┬──┘ └─┬─┘ └┬─┘ └────┬────┘ └───┬───┘ type+permissions owner group size modified name (Ch 4) bytes
The first character is the type: - a normal file, d a directory, l a symbolic link (Ch 3).
The Linux folder layout — where things live on every server#
| Folder | Holds | You'll go there to… |
|---|---|---|
/etc | system-wide configuration files | edit nginx config, check /etc/hosts |
/var/log | logs | read why something failed |
/home/<user> | users' home directories | your files |
/root | the root user's home | |
/usr/bin, /bin | installed programs | |
/usr/local, /opt | software you installed yourself | |
/tmp | temporary files, often wiped on reboot | scratch space |
/var/lib | programs' data (databases often store files here) | find PostgreSQL's data |
/proc | not real files — a live window into the kernel: one folder per process | cat /proc/meminfo, /proc/<pid>/ |
/dev | devices as files ("everything is a file", Operating Systems Ch 10) | /dev/null (Ch 5) |
(macOS uses a different layout for its own folders — /Users, /Applications, /Library — but has /etc, /tmp,
/usr/bin too.)
Gotchas
Spaces in names break commands:
cd My Notestries to go intoMywith an extra argumentNotes. Use quotes (cd "My Notes") or a backslash (cd My\ Notes) — or Tab-completion, which adds them for you. Better: never put spaces in file names you'll use from the terminal.Linux is case-sensitive (Operating Systems Ch 10):
Readme.mdandREADME.mdare different files.
Check yourself
4 questionsWhat do ., .. and ~ mean?
Show answerHide answer
Current directory, parent directory, home directory.
What does ls -la show that ls doesn't?
Show answerHide answer
Hidden files (starting with .) and the long details: permissions, owner, size, date.
Where would you look for a server's logs? Its configuration?
Show answerHide answer
/var/log; /etc.
What is /proc?
Show answerHide answer
A virtual folder where the kernel exposes live information about processes and the system as if they were files.