Basic Command Line Operations and File System Navigation

SA
StudyAI Editorial
Reviewed by StudyAI tutors
· Published Updated

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

Close-up of a blue directional sign for accessible parking amidst urban greenery.
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

Artistic view of a driver's reflection in a rearview mirror with blurred motion.
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

Close-up of hands holding and arranging pink compact discs in a jewel case on a white background.
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

Flat lay of smart home devices including a tablet, smartphone, and bulbs on a vibrant background.
Photo by Jakub Zerdzicki on Pexels

  • mkdir: (make directory) creates a new folder.
    bash mkdir my_new_project
  • touch: 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_folder
  • rm: (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.

  1. Open your terminal.
  2. Check where you are:
    bash pwd # Output might be /Users/yourusername
  3. List what's in your home directory:
    bash ls # Output: Desktop Documents Downloads ...
  4. Create a new folder called quiz_course:
    bash mkdir quiz_course
  5. Move into that new folder:
    bash cd quiz_course
  6. Verify you're in the right place:
    bash pwd # Output: /Users/yourusername/quiz_course
  7. Create a notes file inside quiz_course:
    bash touch quiz_notes.md
  8. Check that the file is there:
    bash ls # Output: quiz_notes.md
  9. Go back up to your home directory:
    bash cd ..
  10. Now, if you wanted to clean up later, you could remove the entire quiz_course folder (and everything in it, like quiz_notes.md):
    bash rm -r quiz_course

4. Key Takeaways

  • pwd shows your current location in the file system.
  • ls lists the contents of the current directory.
  • cd lets you move between directories; cd .. goes up, cd ~ goes home.
  • mkdir creates new directories (folders), and touch creates empty files.
  • rm deletes files, and rmdir deletes empty directories; rm -r deletes 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

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. Read the full notes above for the details.

Basic Command Line Operations and File System Navigation is a core topic in quiz. Most exam papers test it via a mix of definitions, worked examples, and applied problems. The notes above cover the high-yield sub-topics, common pitfalls, and the kind of questions examiners typically set.

Yes. Every note in the StudyAI Campus Hub is free to read. Create a free account if you want to clone the full plan, generate your own notes from your textbook, or get AI-powered practice quizzes and flashcards.

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