RizTech Academy logo
RizTech Academy
Linux FundamentalsLesson 2 of 730 min

The filesystem and navigating it

Everything on a Linux system is organised into one big tree of files and directories, and to work on a server you must be able to move around it, see what is there, and manipulate files — all by typing. This is the most basic Linux skill and the one you will use every minute of every day. This lesson is the filesystem: how it is laid out, and the handful of commands that navigate and manage it.

One tree, starting at /

Unlike Windows with its C: and D: drives, Linux has a single tree of directories starting from the root, written /. Everything — every file, every disk, every device — hangs off that one root. A path like /home/asha/report.txt reads left to right from the root: inside /, the home directory, inside that asha, inside that the file report.txt.

A few directories you will meet constantly on a server (you do not memorise them all, just recognise them):

  • /home — users' personal directories (/home/asha). Your files live here.
  • /etc — configuration files for the system and installed software. You will edit files here often.
  • /var — variable data: logs live in /var/log, which is where you look when something breaks.
  • /usr — installed programs and their files.
  • /tmp — temporary files, wiped on reboot.
  • /root — the home directory of the root (administrator) user.

Knowing that logs are in /var/log and config is in /etc already makes you useful on a server.

Where am I, and what is here

Two commands anchor you:

pwd        # print working directory: the full path of where you currently are
ls         # list the files and directories here
ls -l      # long listing: permissions, owner, size, modified date — one per line
ls -la     # also show hidden files (those starting with a dot, like .bashrc)

ls -la is the one you will type most — it shows everything, with detail. Files and directories whose names start with . are hidden by convention (configuration files, usually); -a reveals them.

Moving around: cd and paths

You change directory with cd, and you can give it two kinds of path:

  • Absolute path — from the root: cd /var/log goes there no matter where you are.
  • Relative path — from where you are now: cd projects goes into projects inside the current directory.

A few shortcuts that save enormous time:

cd /etc      # absolute: go to /etc
cd ..        # up one level (.. means "the parent directory")
cd ../..     # up two levels
cd ~         # your home directory (~ is shorthand for /home/you)
cd           # with no argument, also goes home
cd -         # back to the previous directory you were in

. means "the current directory" and .. means "the parent" — these appear everywhere, so learn them now. Run pwd after each cd until moving around is automatic.

Creating, copying, moving, deleting

The core file operations, each a short command:

mkdir logs                 # make a directory called logs
mkdir -p a/b/c             # make nested directories, creating parents as needed
touch notes.txt            # create an empty file (or update its timestamp)
cp notes.txt backup.txt    # copy a file
cp -r src/ dest/           # copy a directory and everything in it (-r = recursive)
mv notes.txt archive/      # move a file into a directory
mv old.txt new.txt         # rename a file (move is also rename)
rm backup.txt              # remove a file
rm -r olddir/              # remove a directory and its contents

Note mv is both "move" and "rename" — there is no separate rename command.

A serious warning about rm

There is no undo and no recycle bin on the Linux command line. rm deletes immediately and permanently. rm -r somedir/ deletes the directory and everything inside it, gone. And rm -rf / (or a mistyped path) can destroy a system. So:

  • Look before you delete. Run ls on what you are about to remove first.
  • Be careful with -r and wildcards. rm -r * deletes everything in the current directory — make sure you are where you think you are (pwd first).
  • Never blindly copy a rm -rf command from the internet. Read what it targets.

This caution is not paranoia; deleting the wrong thing on a production server is a genuine way to cause an outage, and it happens to people who typed too fast. Slow down around rm.

Looking at a file's contents

You will constantly want to read a file without opening an editor:

cat file.txt        # print the whole file
less file.txt       # page through a long file (q to quit, / to search)
head file.txt       # first 10 lines
tail file.txt       # last 10 lines
tail -f app.log     # follow a log live as new lines are written — you will use this a lot

tail -f on a log file is one of the most-used commands in operations: you run it and watch new log lines appear in real time as the application does things. less is how you read a long config or log file comfortably.

Check your work

One tree from /. Linux has a single directory tree rooted at / (no drive letters); paths read left-to-right from root. Know: /home (your files), /etc (config), /var/log (logs — where you look when things break), /usr (programs), /tmp (temp), /root (admin's home).

Locate/list: pwd (where am I), ls / ls -l (detail) / ls -la (with hidden dotfiles). Dotfiles are hidden config by convention.

Move: cd with absolute (/var/log) or relative (projects) paths; .. = parent, . = current, ~ = home, cd - = previous. pwd to confirm.

Manage files: mkdir/mkdir -p, touch, cp/cp -r, mv (move and rename), rm/rm -r.

rm has no undo, no recycle bin — it deletes permanently. ls before deleting, pwd before wildcards, never blind-copy rm -rf. Deleting the wrong thing causes real outages.

Read files: cat (whole), less (page, q//), head/tail (first/last 10), tail -f (follow a log live — heavily used in ops).

Practice

  1. Use pwd, ls -la and cd to explore from /: visit /etc, /var/log and your home directory, running pwd at each.
  2. From your home directory, mkdir -p practice/a/b, cd into it, then cd ../.. and confirm with pwd.
  3. touch a file, cp it, mv/rename the copy, then rm it — running ls before and after each step.
  4. Explain, with an example, why rm -r is dangerous and the checks you do before running it.
  5. Use cat, head, tail and less on a file in /var/log (or any text file); quit less with q.
  6. Explain what ~, ., .. and cd - each mean, with an example of each.

Official documentation

Next: files, permissions and ownership.

Stuck on this lesson?

Being stuck is part of it — but being stuck alone for three days is not. Our internship programme pairs this curriculum with code review and one-to-one help from working developers, and it is free.

About the internship