Find your way around the files
Everything in Linux lives in one big tree of folders, and at any moment you’re standing in one of them. Once that picture is in your head, the commands make sense: one tells you where you are, one shows you what’s here, and one moves you somewhere else. By the end of this lesson you’ll have built a practice folder that the rest of the course uses.
In this lesson
- Understand the Linux folder tree, and where things are kept
- Move around with
cd, using full and relative paths - Read a detailed file list, and show hidden files
You’ll need: the terminal from Lesson 1.
One tree, starting at /
Windows starts each drive at a letter, like C:. Linux has no drive letters. There’s a single top-level folder called the root, written as /, and everything else sits somewhere below it, even other disks. Folders are often called directories, and the two words mean the same thing.
| Folder | What’s in it |
|---|---|
| /home | Each user’s personal files. Yours is /home/yourname (on a Mac, /Users/yourname) |
| /etc | System-wide settings, mostly as plain text files |
| /var | Things that change as the system runs, including logs in /var/log |
| /usr | Installed programs and their files |
| /tmp | Temporary files that can be cleared at any time |
| /mnt | Where other disks can appear. In WSL, your Windows C: drive is at /mnt/c |
Try it yourself ยท part 1
Look around
- Go to your home folder, which is what
cddoes on its own, and confirm where you are:cdpwd - Look at the very top of the tree:You should recognise several names from the table above.
ls / - Now walk into the settings folder and look around. Notice that your prompt changes too:
cd /etcpwdls - Go back home, and check you got there:
cdpwd
Two ways to say where something is
A full path starts with / and works from anywhere, like a complete postal address. A relative path doesn’t start with / and starts from where you are now, like “next door on the left”.
| You type | What it means |
|---|---|
/etc | Full path: the folder etc at the very top, from wherever you are |
notes | Relative: a folder called notes inside the current one |
.. | The folder one level up |
. | The current folder |
~ | Your home folder, from anywhere |
Try it yourself ยท part 2
Build your practice folder
- Make a folder in your home folder and step into it. The rest of the course uses this one.
mkdir practicecd practice - Make two more folders inside it, then list them:
mkdir notes photosls touchcreates empty files. This makes two insidenotes, and one here with a name starting with a dot:touch notes/todo.txt notes/ideas.txt .secret- List the folder again.
.secretisn’t there:ls - Add
-afor “all”. Names that start with a dot are hidden, and this shows them:Hidden doesn’t mean secure. It only keeps them out of the normal list, and it’s mostly used for settings files. You’ll also seels -a.and..here, the two shortcuts from the table. - Step into
notes, look, and come back up:cd noteslscd ..
Read a detailed list
Add -l for a long list. You can combine options, so ls -la is both at once:
ls -ladrwxr-xr-x 4 sam sam 100 Nov 1 09:25 .
drwx------ 3 sam sam 60 Nov 1 09:25 ..
-rw-r--r-- 1 sam sam 0 Nov 1 09:25 .secret
drwxr-xr-x 2 sam sam 80 Nov 1 09:25 notes
drwxr-xr-x 2 sam sam 40 Nov 1 09:25 photosYour numbers and dates will differ. Reading across, each line shows the type and permissions, a link count you can ignore for now, the owner and group, the size in bytes, the date it last changed, and the name. A d at the very start means it’s a directory, and a - means an ordinary file. Lesson 5 explains the rwx letters.
When it goes wrong
No such file or directory is the error you’ll see most, and it nearly always means one of three things:
- A typo or the wrong capitals. Press Tab instead of typing the whole name: if it won’t complete, the name isn’t there.
- You’re not where you think you are. Run
pwd, thenls. - The name has a space in it.
cd my photoslooks like two separate names. Put it in quotes:cd "my photos". Tab handles this for you too.
/mnt/c/Users/, and running explorer.exe . (with the dot) opens your current Linux folder in File Explorer. Microsoft recommends keeping files you work on from the Linux command line inside Linux, in your home folder, because that’s faster. So keep this course’s folder there.Key takeaways
- Everything sits in one tree under
/, with no drive letters. pwdsays where you are,lsshows what’s here andcdmoves you.- Full paths start with
/. Relative paths start from where you are. ~is home,..is up one level, and.is here.- Dot-files are hidden from the normal list but they aren’t protected.
Check yourself
Three questions. Pick one answer each and you’ll see why.
1. You’re in /home/sam/practice and you run cd ... Where are you now?
.. means one level up, and the folder above practice is /home/sam. Running it twice more would take you to /home and then to /.2. What’s the difference between cd /notes and cd notes?
3. A file is called .secret. How well protected is it?
ls. ls -a shows it straight away. Real protection comes from permissions, which are in Lesson 5.Next you’ll put something in those files: write, edit, copy and delete them safely.
This lesson is part of the free course Linux and the Command Line, licensed under CC BY-NC-SA 4.0: you may share and adapt it for non-commercial use, with credit to ExamineIP and a link to the original.