Theory
Finding your way on the server
You log in to the campus server and land in your home directory, /home/riya. Now what? You need to know where you are, look at what is here, move elsewhere, and make folders for your work. That is what this first set of commands does.
These navigation commands are the ones you will type most often, hundreds of times a day once you are comfortable. They are small and quick. This lesson introduces the family and shows them working together in a real session.
At a glance
| Command | What it does |
|---|---|
| pwd | Print working directory: shows where you currently are |
| ls | List the contents of the current directory (ls -l long form, ls -a shows hidden) |
| cd dir | Change directory into dir; cd alone goes home, cd .. goes up one level |
| mkdir dir | Make a new directory (mkdir -p makes parent directories too) |
| rmdir dir | Remove a directory, but only if it is empty |
| tree | Draw the directory and its contents as a tree |
Practical
A navigation session
$ pwd
/home/riya
$ mkdir -p project/src # make project and project/src in one go
$ cd project
$ pwd
/home/riya/project
$ ls
src
$ cd .. # go back up to /home/riya
$ pwd
/home/riyaFormula
Two shortcuts you will use constantly
`.` means here (the current directory) and `..` means the parent (one level up). So cd .. moves up one directory, and ./script.sh means 'the script right here'.
Also: `cd` with no argument takes you straight home to /home/riya, from anywhere, and a path starting with / is absolute (from the root) while one without is relative (from where you are now). These few ideas, ., .., home, absolute vs relative, are the whole grammar of moving around.
Quiz
You are in /home/riya/project/src and you run cd .. (go up one level). Where are you now?
- /home/riya, jumping straight home
- /home/riya/project, one level up from src
- /home/riya/project/src, unchanged
- / , the root directory
Show the answer
/home/riya/project, one level up from src
'..' means the parent directory, so cd .. moves you up exactly ONE level: from /home/riya/project/src to /home/riya/project. Option A describes cd with no argument (which goes home) or cd ~, not cd .. from this location, moving up one level lands in project, not all the way home. Option C is wrong: cd .. does change your location. Option D is wrong: cd .. goes up only one level, not all the way to the root. Remember: .. is one step up; to go up several levels you repeat it (cd ../..) or use an absolute path.
Think first
Why does rmdir refuse to delete a directory with files in it?
You try rmdir on a folder that contains files and it fails with 'Directory not empty'. Why is rmdir so cautious? Then tap.
Show the answer
Because rmdir is deliberately SAFE: it only removes EMPTY directories, so it cannot accidentally destroy a folder full of your work. If you run rmdir on a directory that still contains files or subdirectories, it refuses and prints 'Directory not empty', which is a helpful guard, it is telling you 'there is still stuff in here; are you sure?'. To remove a directory AND everything inside it, you need a different, more powerful command, rm -r (recursive), which you will meet in the next lesson. That command is genuinely dangerous because it deletes the whole branch without a recycle bin, so Linux keeps the everyday rmdir harmless and makes you reach for rm -r consciously when you really mean to wipe a full directory. The design philosophy is that the easy, common command should be safe, and the destructive one should require you to ask for it explicitly. rmdir's fussiness is protecting you; respect the warning and check before escalating to rm -r.
Summary
Key takeaways
- pwd shows your current directory; ls lists its contents (ls -l long, ls -a includes hidden files).
- cd moves you: cd dir enters a directory, cd .. goes up one level, cd alone goes home.
- mkdir makes a directory (mkdir -p also makes any missing parent directories); tree draws the branch.
- '.' means the current directory and '..' means the parent; these drive relative navigation.
- A path starting with / is absolute (from root); otherwise it is relative to where you are.
- rmdir removes only EMPTY directories; a non-empty one fails with 'Directory not empty' (use rm -r, carefully, for full ones).
- Memory hook: pwd where, ls what, cd move, mkdir make, rmdir remove-empty.