01 Help and Basics

Learning objectives

  • Know how to query command help.
  • Inspect and reuse command history safely.
  • Clear a terminal and print text and variables.
  • Determine whether a command comes from an alias, function, builtin, or external program, and preserve its exit status.

Command overview

CommandPurposeMeaningBasic usageExample
manRead a command manualShort for manual; shows a complete command descriptionman command_nameman ls
--helpRead brief helpMany GNU and third-party external commands support it; it is not a uniform POSIX requirementcommand --helpcp --help
historyView command historyLists commands executed by the current shellhistory or history counthistory 20
clearClear the screenClears the current terminal displayclearclear
printfPrint formatted outputMore predictable behavior than echoprintf 'format' argumentsprintf '%s\n' "$HOME"
command -vQuery command resolutionReturns the location or type clue the Shell will usecommand -v namecommand -v python3
typeInspect Bash command typeShows an alias, function, builtin, or filetype -a nametype -a cd

Common scenarios

Find out how to use a command:

man tar
tar --help

Show recently executed commands:

history 30

Print text and an environment-variable fact:

printf '%s\n' 'hello linux'
printf 'path_entries_are_set=%s\n' "${PATH:+yes}"

Clear the terminal screen:

clear

Notes for beginners

  • In a man page, press / to search and q to quit.
  • Many GNU and third-party external commands use --help for a quick option list, but POSIX does not standardize it. For Bash builtins, prefer help name or the Shell manual; on BSD/macOS, follow the local man page.
  • history only displays history; it does not automatically run it. Confirm safety before rerunning a historical command.
  • History can include URLs, arguments, and accidentally entered secrets. Do not put tokens directly on a command line or publicly paste complete history.
  • Query only variables that are safe to disclose. Bare env or printing a full PATH/proxy configuration can expose local information.
  • $? preserves only the most recent foreground pipeline’s status. Copy it into a variable immediately before another command runs.

Minimal exercise

type -a -- cd
command -v -- grep
grep -q -- 'needle' /dev/null
grep_rc=$?
printf 'grep_rc=%s\n' "$grep_rc"

Explain what kind of command cd and grep are, and use GNU grep documentation to explain exit status 1. Complete Linux environment and Shell basics first for environment, quoting, and expansion.

References