Lesson 2.1: Files, folders and paths
Before using the terminal you need to know where things are. A file lives in a folder, and its path is its address.
The idea
- A file keeps something: a text, a photo, a program.
- A folder keeps files and other folders.
- Together they form a tree:
projects/
├── my-game/
│ ├── hello.js
│ └── index.html
└── notes.txt
The extension
What comes after the last dot in the name is the extension, and it says what kind of file it is:
| Extension | What it is |
|---|---|
.txt | Plain text |
.js | JavaScript |
.html | A web page |
Windows and macOS hide it by default. It's worth showing:
- Windows: in File Explorer, View → Show → File name extensions.
- macOS: in Finder, Settings → Advanced → Show all filename extensions.
The path
The path is a file's address: the folders you go through to reach it.
| System | Path of hello.js |
|---|---|
| Windows | C:\Users\ana\projects\my-game\hello.js |
| macOS | /Users/ana/projects/my-game/hello.js |
| Linux | /home/ana/projects/my-game/hello.js |
Windows separates folders with \; macOS and Linux, with /.
Absolute or relative
- An absolute path starts from the top of the disk, like the ones above.
- A relative path starts from where you are. From
projects,hello.jsis atmy-game/hello.js.
Two shortcuts:
..is the folder above..is the folder you're in.
Names without surprises
For code files, use lowercase names with no spaces: my-game, not My Game. Spaces and accents cause trouble in the terminal and in web addresses.
Try it
With the tree above: you're in my-game. What's the relative path to notes.txt?
Show the solution
../notes.txt. .. goes up from my-game to projects, and notes.txt is there.
Summary
- Files live in folders, and folders form a tree.
- The extension says what kind of file it is.
- The path is a file's address: absolute from the disk, relative from where you are.
..goes up one folder.