Terminal basics: files, folders, and commands · Lesson 6 of 6

Lesson 6: Run programs safely and recover from mistakes

Lesson objectives:

  • Add arguments and flags to a command.
  • Find help with --help and man.
  • Interrupt a running command with Ctrl+C.
  • Read a simple error message and fix the command.

Prerequisites: Lessons 01-05 | Previous << 05 | Next >> README

What if I type the wrong thing?

By now, you have run many commands. Most commands can be changed with extra pieces of information. An argument is a word that tells the command what to act on. A flag (or option) is a special switch that changes how the command behaves 12.

For example, ls lists files. ls -l lists files with details. ls -l Documents lists the details of files inside the Documents folder. Here, -l is a flag and Documents is an argument 1.

When you are unsure what a command can do, you have two reliable sources of help:

  • man ls opens the manual page for ls 32.
  • ls --help prints a short summary of options for many commands 2.

If a command seems to hang or is doing something you did not want, press Ctrl+C to stop it 1. This sends an interrupt signal and returns you to the prompt.

Security note: Never copy and run a command from the internet unless you understand what it does. If a command includes rm, sudo, or > followed by a file path, pause and read it carefully.

Worked example (follow along)

Run these commands and watch the differences.

text
$ lsnotes.txt$ ls -l-rw-r--r--  1 alex  staff  20 Jul 17 09:45 notes.txt$ ls -l -a-rw-r--r--   1 alex  staff    20 Jul 17 09:45 notes.txt-rw-r--r--   1 alex  staff  4096 Jul 17 09:45 .hidden-config

The -l flag changes the output to a long list. The -a flag shows hidden files, which start with a dot. Many flags can be combined: ls -la does the same thing as ls -l -a.

Now try getting help:

text
$ ls --help

You will see a summary. If you want the full manual, try:

text
$ man ls

Scroll with arrow keys and press q to quit.

To see Ctrl+C in action, run a command that waits:

text
$ ping google.comPING google.com (142.250.80.46): 56 data bytes64 bytes from 142.250.80.46: icmp_seq=0 ttl=116 time=12.345 ms64 bytes from 142.250.80.46: icmp_seq=1 ttl=116 time=11.876 ms^C--- google.com ping statistics ---2 packets transmitted, 2 packets received, 0.0% packet loss

The ^C shows where you pressed Ctrl+C. The command stopped and the prompt returned.

Your turn (faded example)

You want to list all files, including hidden ones, in the current folder. Fill in the flag:

text
$ ls -__

Answer: ls -a (or ls -la for a long list with hidden files).

Summary + what's next

Congratulations. You can now open a terminal, read the prompt, move around folders, inspect files, move and copy them, run commands with arguments and flags, find help, and recover from a wrong command. The terminal is no longer a black box of code; it is a text-based way to talk to your computer.

To keep going, practice the five commands you use most: pwd, ls, cd, cat, and mv. When you are comfortable, explore man pages for any command you see in a tutorial. You have the foundation to follow almost any beginner command-line guide without fear.

Footnotes

  1. Apple Command Line Primer — https://developer.apple.com/library/archive/documentation/OpenSource/Conceptual/ShellScripting/CommandLInePrimer/CommandLine.html 2 3

  2. MDN: Command line crash course — https://developer.mozilla.org/en-US/docs/Learn_web_development/Getting_started/Environment_setup/Command_line 2 3

  3. MIT Missing Semester: Course Overview + Introduction to the Shell — https://missing.csail.mit.edu/2026/course-shell/

Exercises

01

Run ls --help and man ls. Read the first screen of each. Then run ls -la in your home folder.

Level 1 (warm-up)
Done criteria · checked locally
02

Deliberately type a command with a typo, such as ls -l nonexistent-folder, and read the error message. Then fix the command to use a folder that actually exists.

Level 2 (advanced)
Done criteria · checked locally