← Operating System Basics: From Zero to Hero
Level 2 · Explorer: Inside Linux

Files and Folders: Explore the Linux Tree

Lesson 10 of 14 · ⏱ 14 min

Your computer can hold millions of files. The OS organizes them all in one big tree. On Linux, the trunk of the tree is a single folder called / (say "root"). Everything else branches from it. Let's explore! 🌳

The top-level folders in Linux: home, etc, bin and usr, var, tmp, dev, proc and boot, with what each is for.

🧪 Lab 1: tour the tree

ls /

You'll see the famous top-level folders. Here is what they're for:

Folder What lives there
/home Your files. Each user gets a folder here
/etc System settings
/bin, /usr Programs (the commands you run)
/var Things that change, like logs
/tmp Temporary files
/dev Devices, shown as files
/proc Live information from the OS
/boot The files used to start Linux

Let's peek into a few:

ls /etc | head
ls /usr/bin | head
ls /var/log | head

Look around, but only look: these are the OS's own folders, so we don't change them.

🧪 Lab 2: paths are addresses

cd /
pwd
cd /usr/bin
pwd
cd ~
pwd
  • An absolute path starts with / and always works, no matter where you are: /usr/bin.
  • A relative path starts from where you are now: Documents/notes.txt.
  • ~ is your home folder. . means here and .. means one folder up.
cd ~/MagiLab
cd ..
pwd
cd MagiLab
pwd

🧪 Lab 3: build a project folder tree

You'll build this tree inside your lab:

A folder tree: the home folder contains Documents, Pictures, Games and Downloads. Inside Documents is Science with volcano.docx. A path is the address of a file.

Make your own version with one command that creates all the folders at once:

cd ~/MagiLab
mkdir -p Science/OS Pictures Stories
ls
ls Science
  • mkdir -p makes folders and any missing parent folders.

Now make some files:

touch Pictures/cat.png
echo "Linux is awesome!" > Stories/first.txt
echo "The kernel is the heart." > Science/OS/notes.txt
cat Science/OS/notes.txt
  • touch makes an empty file, and echo ... > file makes a file with words in it.
  • cat shows what's inside a file.

Look at the whole project:

ls -R

-R means recursive: it shows folders inside folders.

🧪 Lab 4: copy, move and delete (inside the lab!)

cp Stories/first.txt Stories/copy.txt
mv Stories/copy.txt Science/moved.txt
ls Stories Science
rm Science/moved.txt
Command What it does
cp a b Copy a file
mv a b Move or rename a file
rm a Remove (delete) a file, with no undo

🛡️ Safety tip: rm -i name asks you first before deleting. When you're learning, add -i!

🧪 Lab 5: be a file detective

find ~/MagiLab -name "*.txt"
grep -r "kernel" ~/MagiLab
  • find looks for files by name. The * means anything.
  • grep -r searches inside files for a word. You should see your notes.txt!
ls -la ~

The -a shows hidden files: any name that starts with a dot, like .bashrc, is hidden. Linux uses them for settings.

🧪 Lab 6: what kind of file is it?

file ~/MagiLab/Stories/first.txt
file /bin/ls

file looks inside a file to say what it is. The ending (extension) like .txt is only a hint! (If file isn't installed, skip this one.)

Words to know

Word What it means
Root (/) The top of the whole folder tree
Home (~) Your own folder
Absolute path An address starting from /
Relative path An address starting from where you are
Hidden file A file whose name starts with a dot

🎯 Quiz time!

1. What is / in Linux?
2. Which folder holds your own files?
3. What does mkdir -p a/b/c do?
4. Which command searches inside files for a word?