Skip to content

Linux Foundations / Find your way around Linux ยท Step 26 of 63

Lesson: helpSwitch
โ† Linux Foundations

Shell and files

help

Get quick usage information with the bash help built-in and the --help option.

Nobody memorises every option. Linux gives you quick help right at the prompt, and which kind you use depends on what sort of command you have.

Built-in or program?

Some commands are built into the shell, such as cd. Others are separate programs on disk, such as ls. The type command tells you which:

$ type cd
cd is a shell builtin
$ type ls
ls is /usr/bin/ls

You might instead see that ls is aliased or hashed.

The help built-in

In bash, help describes shell built-ins:

$ help pwd
pwd: pwd [-LP]
    Print the name of the current working directory.

The real output continues with the options. Run help with no argument to list the built-ins. help -d cd gives a one line description. help is a bash feature, so other shells may not have it.

It does not cover external programs:

$ help ls
bash: help: no help topics match `ls'.  Try `help help' or `man -k ls' or `info ls'.

The --help option

Most GNU programs accept --help and print a usage summary:

$ mkdir --help
Usage: mkdir [OPTION]... DIRECTORY...
Create the DIRECTORY(ies), if they do not already exist.

This is a convention, not a rule. Some programs use -h, and BSD or macOS tools often only print a short usage line with an error. Do not assume -h means help: for ls and df it means human readable sizes.

If the text is long, pipe it into a pager:

$ ls --help | less

Reading a usage line

  • [ ] marks something optional.
  • ... means it can be repeated.
  • Words in capitals are placeholders for your own values.

So mkdir [OPTION]... DIRECTORY... means any number of options, then one or more directories.

When you need more than a summary, read the manual page with man.

Try it

  1. Run type on cd, ls, echo and pwd.
  2. Read help cd.
  3. Run cp --help | less and find the option for recursion.
  4. Write out in words what the first usage line of cp --help means.

Check your understanding

help

All 4 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.