ShareYourGroupShareYourGroupCommands

Linux and Mac commands

man, --help and history: get help and reuse commands

Nobody remembers every option of every command. What experienced people know is how to look one up in ten seconds, without leaving the terminal, and how to bring back a command they typed last week.

--help: the quick summary

Most commands print a short guide when given --help.

Linux or Mac terminal
asha@pc:~/demo$ ls --help | head -n 12
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all                  do not ignore entries starting with .
  -A, --almost-all           do not list implied . and ..
      --author               with -l, print the author of each file
  -b, --escape               print C-style escapes for nongraphic characters
      --block-size=SIZE      with -l, scale sizes by SIZE when printing them;
                               e.g., '--block-size=M'; see SIZE format below
  -B, --ignore-backups       do not list implied entries ending with ~

The output can be long. Pipe it through less to read it a screen at a time, or through grep to find one option.

Linux or Mac terminal
asha@pc:~/demo$ ls --help | grep -i "human"
  -h, --human-readable       with -l and -s, print sizes like 1K 234M 2G etc.

On a Mac, many built-in commands do not accept --help. Use man instead.

man: the manual

Linux or Mac terminal not run here
man ls

man opens the full manual page for a command in a viewer.

KeyAction
Spacenext screen
bback one screen
/wordsearch for a word
nnext match
g, Gstart, end
qquit

A manual page has the same sections each time: NAME (one line), SYNOPSIS (how to write the command), DESCRIPTION, OPTIONS, and often EXAMPLES near the end. When in a hurry, search for the option with a slash, or jump to the examples with G and scroll back.

In the SYNOPSIS, square brackets mean optional, and three dots mean "more of the same may follow".

Not sure of the command's name?

Linux or Mac terminal not run here
whatis ls
apropos "copy files"
man -k compress

whatis gives the one-line description of a command. apropos, the same as man -k, searches all the descriptions for a word and lists the commands that mention it.

Commands built into the shell

Some commands, such as cd, are part of the shell and have no manual page of their own. type tells you what a name is.

Linux or Mac terminal
asha@pc:~/demo$ type cd
cd is a shell builtin
asha@pc:~/demo$ type ls
ls is /usr/bin/ls

In Bash, help cd explains a built-in command.

Simpler examples

Manual pages are complete and can be heavy going. Many people install a helper that shows a few common examples per command, such as tldr. It is not part of the standard system, and it is no replacement for the manual when the detail matters.

history

The shell remembers the commands you type.

Linux or Mac terminal not run here
history
history | tail -n 20
history | grep tar

Each line has a number. The history is kept in a file in your home folder, .bash_history or .zsh_history, and survives between sessions.

Bringing a command back

TypeTo get
Up arrowthe previous command, and earlier ones with each press
Ctrl + Ra search: type part of an old command
!!the last command again
sudo !!the last command again, with sudo in front
!123command number 123 from the history
!tarthe most recent command beginning with tar
!$the last word of the previous command

Ctrl + R is the one that changes how you work. Press it, type a few letters, such as "tar" or part of a file name, and the most recent matching command appears. Press Ctrl + R again for older matches, Enter to run it, or an arrow key to edit it first.

!$ saves retyping a long path: after mkdir /some/long/folder/name, cd !$ goes into it.

Danger. The ! forms run immediately. !rm runs the last command that began with rm, whatever it was, in whatever folder you are in now. Use Ctrl + R instead, which shows the command and waits for Enter.

Tab completion

Press Tab after the first letters of a command, file or folder name. If one thing matches, the shell completes it. If several match, a second Tab lists them. It saves typing and, more importantly, proves that the file exists and is spelt as you think.

What history should not hold

Anything typed on a command line goes into the history file, including a password given as an argument. Avoid typing secrets into commands. Let the program ask for them instead. In Bash, a command that begins with a space is left out of the history when the setting HISTCONTROL=ignorespace is in force, as it is on many systems.

history -c clears the history of the current session.

Learning a new command

A dependable routine for any command you have not used before:

  1. whatis command for one line.
  2. command --help for the options.
  3. man command, and search for the word you care about.
  4. Try it in a practice folder, on copies.
  5. For anything that deletes or overwrites, look for a dry-run option, often -n or --dry-run, which shows what would happen without doing it.

On Windows

The equivalents are command /? and help. The Command Prompt keeps a history for the session: the up arrow and F7 show it. PowerShell has Get-Help and its own history with Ctrl + R.

Examples shown with output were run on 12 November 2026 in a practice folder: Windows commands in cmd.exe on Windows 11, Linux commands with the GNU tools of Git Bash. The folder path and user name were replaced with made-up ones. Commands marked "not run here" are shown as you would type them.

This is an independent learning site. It is not connected with Microsoft, Apple or any Linux distribution. Windows, macOS and other names belong to their owners. Try commands first in a practice folder, never on files you cannot afford to lose.