Getting Help
Nobody remembers every option of every command. Experienced users look things up all the time, and the fastest place to look is the terminal itself: every shell has built-in help, and almost every program describes its own options. This lesson shows where help lives in each shell and how to find a command when you only know what you want to do.
The quick overview
| Question | CMD | PowerShell | bash | zsh (macOS) |
|---|---|---|---|---|
| How do I use command X? | X /? |
Get-Help X (alias help X) |
X --help, man X |
man X, X --help (GNU tools only) |
| Show only the syntax | X /? |
Get-Command X -Syntax |
help X (built-ins) |
run-help X |
| Show examples | (in X /?, sometimes) |
Get-Help X -Examples |
man X → EXAMPLES section |
man X |
| List all commands | help |
Get-Command |
compgen -c, help (built-ins) |
press Tab twice |
| Find a command by topic | help | findstr /i copy |
Get-Command *copy* |
apropos copy, man -k copy |
apropos copy |
| Is X built in, an alias or a program? | where X |
Get-Command X |
type X |
whence -v X |
Windows (CMD)
Every CMD command and most Windows programs accept /?. The output starts with a one-line description and then the syntax, where [ ] marks optional parts and | separates alternatives:
C:\Users\ada>copy /?
Copies one or more files to another location.
COPY [/D] [/V] [/N] [/Y | /-Y] [/Z] [/L] [/A | /B ] source [/A | /B]
[+ source [/A | /B] [+ ...]] [destination [/A | /B]]
source Specifies the file or files to be copied.
...help on its own lists the built-in commands with a one-line summary each (about 80 of them), and help copy is the same as copy /?. Long help pauses after each screen: press Space for the next page or Q to quit. where tells you which program file would run:
C:\Users\ada>where notepad
C:\Windows\System32\notepad.exe
C:\Windows\notepad.exe(Sample output — the list depends on your PATH.) Microsoft's online Windows Commands reference documents every command in more detail.
Windows (PowerShell)
PowerShell commands are self-describing, so you can query them like data. Get-Command finds commands by name, verb or noun, and -Syntax prints just the usage lines:
Get-Command *-Location | Select-Object -ExpandProperty Name
'---'
Get-Command -Verb Remove -Noun Item | Select-Object -ExpandProperty Name
'---'
Get-Alias -Definition Remove-Item | Select-Object -ExpandProperty NameGet-Location
Pop-Location
Push-Location
Set-Location
---
Remove-Item
---
del
erase
rd
ri
Every cmdlet name follows a Verb-Noun pattern, so guessing works surprisingly well: if Get-Location exists, Set-Location probably does too. On Windows the alias list also contains rm, rmdir and ls; on Linux and macOS PowerShell leaves those names to the native Unix programs.
Get-Command Rename-Item -Syntax
Rename-Item [-Path] <string> [-NewName] <string> [-Force] [-PassThru] [-Credential <pscredential>] [-WhatIf] [-Confirm] [<CommonParameters>]
Rename-Item [-NewName] <string> -LiteralPath <string> [-Force] [-PassThru] [-Credential <pscredential>] [-WhatIf] [-Confirm] [<CommonParameters>]
Square brackets around a parameter name ([-Path]) mean you may leave the name out and pass the value by position: Rename-Item a.txt b.txt works.
Get-Help shows the full documentation. The detailed help files are downloaded separately, once, with Update-Help (run it in an admin window on Windows PowerShell 5.1):
PS C:\Users\ada> Update-Help -UICulture en-US -ErrorAction SilentlyContinue
PS C:\Users\ada> Get-Help Copy-Item -Examples
NAME
Copy-Item
SYNOPSIS
Copies an item from one location to another.
------------- Example 1: Copy a file to the specified directory -------------
...
PS C:\Users\ada> Get-Help Copy-Item -Online # opens the docs in your browser
PS C:\Users\ada> Get-Help about_Wildcards # concept topics start with about_Linux & macOS (bash/zsh)
There are three sources of help on Unix systems.
1. --help — most GNU programs (Linux) print a usage summary:
grep --help | head -3Usage: grep [OPTION]... PATTERNS [FILE]...
Search for PATTERNS in each FILE.
Example: grep -i 'hello world' menu.h main.c
macOS's BSD tools usually don't support --help; they print a short usage line or an error instead, so use man there.
2. help — bash's own built-in commands (cd, echo, export, for …) aren't programs, so they're documented by the help built-in. -d prints one-line descriptions:
help -d cd pwd echo
type cd ls echocd - Change the shell working directory.
pwd - Print the name of the current working directory.
echo - Write arguments to the standard output.
cd is a shell builtin
ls is /bin/ls
echo is a shell builtin
type answers "what will run if I type this?": a built-in, an alias, a function or a program file. zsh has the same type, plus whence -v:
whence -v cd lscd is a shell builtin
ls is /bin/ls
3. man — the manual pages, the complete reference, on both Linux and macOS (the playground sandboxes don't include them). man ls opens a pager: arrow keys or Space to scroll, /word to search, q to quit. man -k (or apropos) searches the one-line descriptions of all pages:
ada@ubuntu:~$ man -k "copy files"
cp (1) - copy files and directories
cpio (1) - copy files to and from archives
install (1) - copy files and set attributes(Sample output — the list depends on what's installed.) The number in brackets is the manual section: 1 = user commands, 5 = file formats, 8 = admin commands. Pages for shell built-ins live in the big man bash or man zshbuiltins pages.
Reading syntax lines
All help systems use similar notation:
| Notation | Meaning | Example |
|---|---|---|
[ ] |
optional | ls [OPTION]... [FILE]... |
... |
may be repeated | several files |
a | b |
one or the other | /Y | /-Y |
<type> or CAPITALS |
a value you supply | <string>, FILE |
Other good sources
- tldr pages (
tldr tar, installable everywhere) show the five most common uses of a command. - Tab completion: type the start of a command or option and press Tab (covered in History, Completion & Shortcuts).
- The error message itself. Read it slowly: it usually names the problem.
Learn more: PowerShell Discovery · CMD Syntax · Bash Syntax
Test yourself
How do you get help for the CMD command xcopy?
man xcopyxcopy --helpxcopy /?Get-Help xcopy
In bash, which command tells you whether cd is a built-in or a program?
type cdman cdcd --versionwhich-is cd
Which PowerShell command lists every command whose noun is Item?
Get-Help -Noun ItemGet-Command -Noun ItemFind-Item *help Item