Basic Command Line Operations and File System Navigation
From the quiz curriculum
Basic Command Line Operations and File System Navigation
TL;DR
The command line lets you interact with your computer using text commands, which is powerful for managing files and running programs. You'll learn to move around your file system (folders and files) and perform basic actions like viewing, creating, and deleting items. Mastering these few commands will give you much more control over your machine.
1. The Mental Model
Think of your computer's files and folders like a giant tree, where folders are branches and files are leaves. The command line is like a special remote control that lets you jump to any branch and do things to the leaves or smaller branches, all by typing simple instructions.
2. The Core Material
When you open a command line (often called a terminal or shell), you're usually placed in your "home directory." This is your personal starting point. From there, you'll use commands to explore and manipulate your file system.
Your Current Location: pwd

Photo by Caleb Oquendo on Pexels
The pwd command stands for "print working directory." It tells you exactly where you are in the file system tree.
pwd
# Example output: /Users/yourusername
Seeing What's Around: ls

Photo by Alexey Demidov on Pexels
The ls command (list) shows you the contents of your current directory. It's like opening a folder and seeing what's inside.
ls
# Example output: Documents Downloads Desktop Pictures
You can add options to ls to get more information:
* ls -l: (long format) shows details like permissions, owner, size, and modification date.
* ls -a: (all) shows hidden files (files starting with a .).
* ls -la: combines both, showing all files in long format.
Moving Around: cd

Photo by cottonbro studio on Pexels
The cd command (change directory) is how you navigate.
cd Documents: Moves you into the "Documents" folder.cd ..: Moves you up one level to the parent directory.cd ~: Takes you directly to your home directory, no matter where you are.cd /: Takes you to the "root" directory, the very base of your file system.
Paths can be absolute (starting from the root /, e.g., /Users/yourusername/Documents) or relative (from your current location, e.g., Documents).
Creating Things: mkdir and touch

Photo by Jakub Zerdzicki on Pexels
mkdir: (make directory) creates a new folder.
bash mkdir my_new_projecttouch: creates an empty file or updates the timestamp of an existing one.
bash touch notes.txt
Removing Things: rm and rmdir
rmdir: (remove directory) removes an empty folder.
bash rmdir empty_folderrm: (remove) deletes files. Be careful – there's usually no "undo"!
bash rm notes.txt
To remove non-empty directories, you need the-r(recursive) option:
bash rm -r my_new_project # This will delete the folder and everything inside it!
Here's a simple flow of common navigation and creation commands:
graph TD
Start["Open Terminal"] --> A["pwd (Where am I?)"]
A --> B["ls (What's here?)"]
B --> C1["cd folder_name (Go deeper)"]
B --> C2["cd .. (Go up)"]
C1 --> D1["mkdir new_subfolder (Create folder)"]
C1 --> D2["touch new_file.txt (Create file)"]
D1 --> E1["ls (See new folder)"]
D2 --> E2["ls (See new file)"]
E1 --> F["cd .. (Go back up)"]
E2 --> F
F --> G["rm new_file.txt (Delete file)"]
F --> H["rmdir new_empty_folder (Delete empty folder)"]
G --> End["Done"]
H --> End
3. Worked Example
Let's say you want to create a new folder for your quiz course, and inside it, a file for your notes.
- Open your terminal.
- Check where you are:
bash pwd # Output might be /Users/yourusername - List what's in your home directory:
bash ls # Output: Desktop Documents Downloads ... - Create a new folder called
quiz_course:
bash mkdir quiz_course - Move into that new folder:
bash cd quiz_course - Verify you're in the right place:
bash pwd # Output: /Users/yourusername/quiz_course - Create a notes file inside
quiz_course:
bash touch quiz_notes.md - Check that the file is there:
bash ls # Output: quiz_notes.md - Go back up to your home directory:
bash cd .. - Now, if you wanted to clean up later, you could remove the entire
quiz_coursefolder (and everything in it, likequiz_notes.md):
bash rm -r quiz_course
4. Key Takeaways
pwdshows your current location in the file system.lslists the contents of the current directory.cdlets you move between directories;cd ..goes up,cd ~goes home.mkdircreates new directories (folders), andtouchcreates empty files.rmdeletes files, andrmdirdeletes empty directories;rm -rdeletes non-empty directories.- Paths can be absolute (start with
/) or relative (start from your current location).
Common Mistakes to Avoid:
- Forgetting rm -r when trying to delete a folder that isn't empty.
- Typing rm * without understanding it deletes everything in the current directory. Be very careful with rm!
- Not knowing where you are (pwd) before running commands, leading to creating/deleting things in the wrong place.
- Confusing cd foldername (go into a folder) with cd .. (go up a folder).
5. Now Try It
Open your terminal. Navigate to your Desktop. Create a new folder called my_practice_area. Inside my_practice_area, create two new empty files: exercise1.txt and exercise2.md. Then, from within my_practice_area, create another folder called subfolder_a. Finally, navigate back to your Desktop and delete the entire my_practice_area folder.
Success looks like: You were able to perform all these steps without errors, and when you're done, the my_practice_area folder is no longer on your Desktop.
Frequently asked about Basic Command Line Operations and File System Navigation
More from quiz
Get the full quiz curriculum
Clone the complete plan to your dashboard for unlimited AI-generated notes, practice quizzes, and a personalised revision schedule.
Create Free Account