Lesson 2 of 720 minutesHands-on

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.

FolderWhat’s in it
/homeEach user’s personal files. Yours is /home/yourname (on a Mac, /Users/yourname)
/etcSystem-wide settings, mostly as plain text files
/varThings that change as the system runs, including logs in /var/log
/usrInstalled programs and their files
/tmpTemporary files that can be cleared at any time
/mntWhere other disks can appear. In WSL, your Windows C: drive is at /mnt/c

Try it yourself ยท part 1

Look around

  1. Go to your home folder, which is what cd does on its own, and confirm where you are:
    cd
    pwd
  2. Look at the very top of the tree:
    ls /
    You should recognise several names from the table above.
  3. Now walk into the settings folder and look around. Notice that your prompt changes too:
    cd /etc
    pwd
    ls
  4. Go back home, and check you got there:
    cd
    pwd

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 typeWhat it means
/etcFull path: the folder etc at the very top, from wherever you are
notesRelative: 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

  1. Make a folder in your home folder and step into it. The rest of the course uses this one.
    mkdir practice
    cd practice
  2. Make two more folders inside it, then list them:
    mkdir notes photos
    ls
  3. touch creates empty files. This makes two inside notes, and one here with a name starting with a dot:
    touch notes/todo.txt notes/ideas.txt .secret
  4. List the folder again. .secret isn’t there:
    ls
  5. Add -a for “all”. Names that start with a dot are hidden, and this shows them:
    ls -a
    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 see . and .. here, the two shortcuts from the table.
  6. Step into notes, look, and come back up:
    cd notes
    ls
    cd ..

Read a detailed list

Add -l for a long list. You can combine options, so ls -la is both at once:

ls -la
drwxr-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 photos

Your 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, then ls.
  • The name has a space in it. cd my photos looks like two separate names. Put it in quotes: cd "my photos". Tab handles this for you too.
On Windows with WSL? Linux and Windows can see each other’s files. Your Windows files are under /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.
  • pwd says where you are, ls shows what’s here and cd moves 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?

2. What’s the difference between cd /notes and cd notes?

3. A file is called .secret. How well protected is it?

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.

Scroll to Top