21  21. Getting Help and Working Faster

Nobody memorizes every command and option. This page shows how to look things up from the terminal, how to ask the web or an AI effectively, and the keyboard shortcuts that make working at the command line much faster.

21.1 Built-in help: --help and man

Most commands come with built-in help, but this is one place where the Mac and Git Bash really differ:

  • man ls opens the manual page (“man page”) for ls. It works like less: arrow keys or Space to scroll, /word to search, q to quit.
  • Many basic commands on a Mac, such as ls and cp, don’t understand --help (see Moving Around: pwd, ls, and cd). Use man for those.
  • Newer tools do support --help, for example git --help and python3 --help.
  • The commands in Git Bash support --help. ls --help prints a summary of all its options.
  • Git Bash does not include man. Use --help, or search online for “man ls”.
  • For commands that are built into Bash itself, such as cd, use help: help cd.
  • git help commit (or git commit --help) opens Git’s manual page in your web browser.

Here are the first lines of ls --help in Git Bash:

ls --help

Output:

Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).

In a usage line, square brackets [ ] mean “optional” and ... means “you can give more than one”. So ls takes zero or more options and zero or more files. Short options have one dash (-a), long options have two (--all).

21.2 Asking the web or an AI

Searching online for “bash how to count lines in a file” usually finds an answer quickly. AI assistants are even faster, and they can explain a command piece by piece. To get answers that work for you:

  • Say which system and shell you use. Otherwise you may get a PowerShell command, which won’t work in Bash or zsh.
  • Paste the exact error message, not a summary of it.
  • Ask for an explanation of each part of the command before you run it (more on using AI safely in Bash Scripts).

For example:

I'm on Windows 11 using Git Bash. How do I find all .csv files in my
Documents folder and its subfolders? Explain each part of the command.

21.3 More from Tab and your command history

Moving Around: pwd, ls, and cd introduced Tab completion and the ↑/↓ arrow keys. A few more details make them even more useful:

  • Tab works for commands too, not just files and folders, and it adds the backslashes needed for names that contain spaces. If Tab completes nothing, that’s a hint that the file isn’t where you think it is.
  • When several names fit, the shell can list them. In Git Bash, press Tab twice. zsh on a Mac shows the list after the first Tab (pressing Tab again there starts cycling through the choices). In bash-tutorial-files, cd p could mean pictures or projects: once you see both, type one more letter (r) and press Tab again.
  • history prints a numbered list of your recent commands. (In zsh on a Mac, plain history shows only the last 16; history 1 shows them all.)
  • Ctrl+R searches your history. Press Ctrl+R, then type part of an old command, such as nano. The most recent match appears. Press Ctrl+R again for older matches, Enter to run the one shown, or Ctrl+C to cancel.

Your history is saved in a hidden file in your home folder (~/.zsh_history on a Mac, ~/.bash_history in Git Bash). That’s convenient, and it is one more reason never to type passwords or API keys directly into a command.

21.4 Keyboard shortcuts

Keys What they do
Tab complete a file, folder, or command name
Tab Tab list the possible completions (zsh on a Mac: one Tab)
↑ / ↓ previous / next command from your history
Ctrl+R search your command history
Ctrl+C stop the running command, or cancel the line you’re typing
Ctrl+L clear the screen (same as the clear command)
Ctrl+A / Ctrl+E jump to the beginning / end of the line
Ctrl+U erase the line you’re typing
Ctrl+D on an empty line: end the shell session, just like exit

These use the Ctrl key on a Mac too, not Cmd. On a Mac, Cmd+K also clears the Terminal window, including everything you could scroll back to.

Ctrl+C stops things; it doesn’t copy

In a terminal, Ctrl+C interrupts the command that is running. Use it whenever a command runs too long, or seems frozen. A common case: you forgot to give a command its file name (for example grep budget with no file), so it sits waiting for you to type input. Press Ctrl+C and try again.

21.5 Copy, paste, and dragging files

Copying and pasting works a little differently in each terminal; the keys are listed in Getting Bash on Your Computer.

To enter a long path without typing it, drag a file or folder from Finder or File Explorer into the Mac Terminal or Git Bash window: its full path appears on the command line (Git Bash writes it Bash-style and adds quotes if the name contains spaces). For example, type cd (with a space), drag a folder into the window, and press Enter.

On a Mac you can also copy a path from Finder: right-click a file or folder, hold down the Option key, and choose Copy “…” as Pathname.

21.6 Opening folders and files from the terminal

The opposite direction is handy too: opening the folder you’re in, in the graphical file browser.

  • open . opens the current folder in Finder (. means “this folder”).
  • open ideas.txt opens a file in its default app.
  • explorer . opens the current folder in File Explorer.

If you have VS Code installed, code . opens the current folder in VS Code. The Windows installer sets this up automatically. On a Mac, do it once: in VS Code, press Cmd+Shift+P, type shell command, and choose Shell Command: Install ‘code’ command in PATH. Then open a new Terminal window.

21.7 Running several commands: ; and &&

You can put several commands on one line:

  • ; runs the commands one after the other, no matter what.
  • && runs the next command only if the previous one succeeded.
mkdir reports-2026 && cd reports-2026

Here cd runs only if mkdir worked. && really matters when something goes wrong. With a typo in the folder name, cd projetcs && ls prints a “No such file or directory” error and stops. cd projetcs ; ls prints the same error and then runs ls anyway, in the wrong folder. That’s harmless for ls, but imagine cd old-files ; rm *.txt: if the cd fails, rm deletes the .txt files in whatever folder you’re in.

You will often see && in installation instructions and in commands written by AI tools, for example npm install && npm run dev.

Practice Questions

Easy

Question 1 · Short answer

What happens when you type the first few letters of a file name and press Tab?

The shell completes the name for you (tab completion). If several names fit, pressing Tab twice lists the choices (in zsh on a Mac, one Tab already lists them).

Question 2 · Multiple choice

A command has been running for a long time and you want to stop it. Which key do you press?

  1. Ctrl+C
  2. Ctrl+D
  3. Esc
  4. q

a. Ctrl+C interrupts the running command (it is not “copy” in a terminal). Ctrl+D means “end of input” and, on an empty prompt, ends the shell session. Esc doesn’t stop shell commands, and q quits only viewers such as less and man.

Question 3 · Multiple choice

You’re reading man ls on a Mac. How do you get back to the prompt?

  1. Press Esc
  2. Press q
  3. Type exit
  4. Press Ctrl+D twice

b. Man pages are shown in a viewer that works like less, and q quits it. The other choices don’t leave the viewer, because it treats your keys as viewer commands, not shell commands (for example, Ctrl+D scrolls down).

Question 4 · Matching

Match each shortcut with what it does.

Keys What it does
1. Ctrl+R A. jump to the beginning of the line
2. Ctrl+L B. end the shell session (on an empty line)
3. Ctrl+A C. search your command history
4. Ctrl+D D. clear the screen

1 → C, 2 → D, 3 → A, 4 → B.

Question 5 · Short answer

Which command prints a numbered list of the commands you typed earlier?

history. (In zsh on a Mac, history 1 shows the whole list; plain history shows only the most recent commands.)

Question 6 · Multiple choice

Which command opens the current folder in Finder on a Mac?

  1. open .
  2. explorer .
  3. cd .
  4. ls .

a. open . opens the current folder (.) in Finder. explorer . is the Git Bash equivalent on Windows. cd . stays in the same folder, and ls . lists the folder’s contents in the terminal.

Medium

Question 7 · Scenario

Maria opens man grep on her Mac to find out how to search through folders. How can she search the manual page for the word recursive, jump to the next place it appears, and then leave the page?

Man pages work like less. She types /recursive and presses Enter to jump to the first match, presses n to go to the next match, and presses q to quit and return to the prompt.

Question 8 · Scenario

Sam types man grep in Git Bash and gets command not found. Give two other ways he can learn about grep’s options.

Git Bash doesn’t include man. He can:

  1. run grep --help (Git Bash’s commands support --help), or
  2. search online for “man grep”, or ask an AI, saying that he uses Git Bash on Windows.

Question 9 · Predict the output

The folder projetcs doesn’t exist (it’s a typo for projects). What happens with each line?

cd projetcs && ls
cd projetcs ; ls

Both lines print a “No such file or directory” error for the cd.

  • With &&, ls does not run, because cd failed.
  • With ;, ls runs anyway and lists the files of the current folder, which is not the folder you meant.

Question 10 · Write the command

Write one line that creates the folder club-site and then moves into it, but only if creating the folder worked.

mkdir club-site && cd club-site

Question 11 · Scenario

Yesterday Sam typed a long git commit -m "..." command. Today he wants to run it again (with a small change). What is the fastest way to get it back?

Press Ctrl+R and type part of the command, such as commit. The most recent matching command appears; press Ctrl+R again for older matches. Then edit it if needed and press Enter. (Pressing ↑ several times also works if the command was recent.)

Question 12 · Short answer

In bash-tutorial-files, Maria types cd p and presses Tab once. The name isn’t completed. Why not, and what should she do?

Two folders start with p (pictures and projects), so the shell can’t choose. On her Mac, zsh lists both choices right after that Tab (in Git Bash you would press Tab a second time to see them). She can type one more letter (i or r) and press Tab again to complete the name.

Question 13 · Write the command

Write the command that opens the current folder in VS Code. What one-time setup does a Mac need before it works?

code .

On a Mac, open VS Code, press Cmd+Shift+P, and run Shell Command: Install ‘code’ command in PATH, then open a new Terminal window. (This puts the code command in a folder on the PATH.) The Windows installer does this automatically.

Question 14 · Scenario

Sam typed grep budget and pressed Enter. Nothing happens and his prompt doesn’t come back. What’s going on, and what should he do?

He didn’t give grep a file name, so grep is waiting for him to type the text it should search. Press Ctrl+C to stop it, then run it with a file, for example grep budget meeting-notes.txt.

Hard

Question 15 · Scenario

A classmate’s cleanup instructions say:

cd old-reports ; rm *.txt

Explain the risk, and rewrite the line to be safer.

If old-reports doesn’t exist (a typo, or you’re in the wrong folder), the cd fails, but ; runs rm *.txt anyway, deleting the .txt files in your current folder, with no undo. Use && so that rm runs only if the cd succeeded:

cd old-reports && rm *.txt

Even better, first check what would be deleted: cd old-reports && ls *.txt.

Question 16 · Long answer

Write a good prompt asking an AI for a command that renames every .jpeg file in a folder to end in .jpg. Explain what makes your prompt good.

Example prompt:

I'm on a Mac using zsh in Terminal. In my current folder I have about 50
.jpeg files. Give me a command that renames each one to end in .jpg instead.
Explain each part of the command, and show me how to preview the changes
before anything is renamed.

It’s good because it states the operating system and shell (so the answer won’t be a PowerShell command), describes the exact goal and files, asks for an explanation so you understand the command before running it, and asks for a preview, a safe way to check the result first.

Question 17 · Scenario

On her Mac, Maria wants to find a long curl command she ran last week, but history shows only her last 16 commands. Give two ways she can find it.

  1. Run history 1, which in zsh lists her whole saved history, not just the last 16 commands.
  2. Press Ctrl+R, type curl, and press Ctrl+R repeatedly to step back through older matches.

(After the next page she could also run history 1 | grep curl.)

Question 18 · Short answer

Why is it risky to type a real API key directly into a command such as export WEATHER_API_KEY=abc123...?

The shell saves the commands you type in a history file in your home folder (~/.zsh_history or ~/.bash_history). The key would be stored there in plain text, where anyone or any program that can read the file could find it, and it can also show up on screen (for example when you press ↑ or run history while sharing your screen). Keep keys in a protected file such as a git-ignored .env file instead.

Question 19 · Scenario

Sam needs to cd into a folder named OneDrive - My University/Course Files and keeps making typos in the long path. Give two ways to get the path right without typing it all.

  1. Type cd (with a space), then drag the folder from File Explorer into the Git Bash window. Git Bash inserts the full path, with quotes because it contains spaces. Press Enter.
  2. Use tab completion: type the first few letters of each folder name and press Tab, which completes the name and adds the backslashes needed for the spaces.

© 2025-2026 Y. Rosenthal. All rights reserved.