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 lsopens the manual page (“man page”) forls. It works likeless: arrow keys orSpaceto scroll,/wordto search,qto quit.- Many basic commands on a Mac, such as
lsandcp, don’t understand--help(see Moving Around: pwd, ls, and cd). Usemanfor those. - Newer tools do support
--help, for examplegit --helpandpython3 --help.
- The commands in Git Bash support
--help.ls --helpprints 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, usehelp:help cd. git help commit(orgit commit --help) opens Git’s manual page in your web browser.
Here are the first lines of ls --help in Git Bash:
ls --helpOutput:
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
Tabcompletes 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
Tabtwice. zsh on a Mac shows the list after the firstTab(pressingTabagain there starts cycling through the choices). Inbash-tutorial-files,cd pcould meanpicturesorprojects: once you see both, type one more letter (r) and pressTabagain. historyprints a numbered list of your recent commands. (In zsh on a Mac, plainhistoryshows only the last 16;history 1shows them all.)Ctrl+Rsearches your history. PressCtrl+R, then type part of an old command, such asnano. The most recent match appears. PressCtrl+Ragain for older matches,Enterto run the one shown, orCtrl+Cto 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.txtopens 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-2026Here 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?
Question 2 · Multiple choice
A command has been running for a long time and you want to stop it. Which key do you press?
Ctrl+CCtrl+DEscq
Question 3 · Multiple choice
You’re reading man ls on a Mac. How do you get back to the prompt?
- Press
Esc - Press
q - Type
exit - Press
Ctrl+Dtwice
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 |
Question 5 · Short answer
Which command prints a numbered list of the commands you typed earlier?
Question 6 · Multiple choice
Which command opens the current folder in Finder on a Mac?
open .explorer .cd .ls .
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?
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.
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 ; lsQuestion 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.
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?
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?
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?
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?
Hard
Question 15 · Scenario
A classmate’s cleanup instructions say:
cd old-reports ; rm *.txtExplain the risk, and rewrite the line to be safer.
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.
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.
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...?
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.