FactorPad
Build a Better Process

What Are bash Shell builtin Commands?

Some of the 60 default programs we will use every day. Others have a more specialized purpose, so we need to look them up.
  1. An odd place - Find a tucked-away help system.
  2. shell (bash) - Learn what a shell program does and the alternatives.
  3. builtins - See how to find the 60 builtins.
  4. Finding help - Compare finding help for regular commands and builtin commands.
  5. Next: symbols - Learn the most common special characters.
face pic by Paul Alan Davis, CFA
Updated: February 21, 2021
Learning to find help on builtins within Linux documentation will save you time. Learn the trick below.

Outline Back Tip Next

/ factorpad.com / tech / full-stack / bash-shell-builtins.html


An ad-free and cookie-free website.


Learn how to access and find help on bash builtins

Beginner

Video Tutorial

Videos can also be accessed from our Full Stack Playlist 2 on YouTube.

What are bash shell builtin commands? | Linux Tutorial for Beginners (4:58)

Code Examples and Video Script

Welcome. Today's question: What are bash shell builtins?

I'm Paul, and if you're just learning the Linux command line, then you've certainly bumped into what I'd consider an odd place.

Step 1 - What does 'an odd place' mean?

I say odd because given the importance of Linux, the most common server on the Internet today, and likely where your browsers and Apps point, wouldn't you expect it to be easier to find help? Especially on the topic of builtins.

Here I'll break the question into two parts, first the shell, here our default is called bash.

Second I'll cover builtins which are commands that come built-in to bash.

After that, I'll show you how to find help on builtins, including a time-saving trick.

(And practice with a few other commands already covered).

And if you see mysterious symbols used here, I'll tackle symbols and their special meanings in tutorial 16.

Step 2 - A Background on Shells

Okay, here's the command line on a server that sits in my office, running a Linux distribution called Debian.

While I use whatis to preview what we'll cover in this video, the program responsible for interpreting what I type is called bash, and if you noticed, the last two letters stand for shell (see description below).

paul@fullstack:~$ whatis type bash help whatis clear ls wc less exit bash (1) - GNU Bourne-Again SHell whatis (1) - display one-line manual page descriptions clear (1) - clear the terminal screen ls (1) - list directory contents wc (1) - print newline, word, and byte counts for each file less (1) - opposite of more type: nothing appropriate. help: nothing appropriate. exit: nothing appropriate.

Other shells are available on Linux, but the most common is bash.

I put links to two Wikipedia articles on shells in the video's description. One details shell functionality, and that is, the shell interprets what you type, sends it to the processor and returns a result.

The second article compares two dozen shell programs, including bash, ash, csh, ksh and tcsh.

Macs use bash and Windows uses PowerShell. In Q4 2016 Microsoft teamed up with Ubuntu on a beta version of bash aimed at developers, who were favoring Macs over Windows.

So you've likely observed a few odd things about this output. First, notice how even a basic summary can be cryptic and confusing? (pointing to the description 'opposite of more' for less)

Second, notice how some have no explanation at all? (pointing to 'nothing appropriate' for type, help and exit).

Step 3 - A Description of bash builtins

This offers a clue about builtins and to demonstrate I'll do the same thing with the type command, using the Up Arrow to save keystrokes, of course, and type shows how words are interpreted, and which are builtins.

paul@fullstack:~$ type type bash help whatis clear ls wc less exit type is a shell builtin bash is hashed (/bin/bash) help is a shell builtin whatis is hashed (/usr/bin/whatis) clear is hashed (/usr/bin/clear) ls is aliased to 'ls --color=auto' wc is /usr/bin/wc less is hashed (/usr/bin/less) exit is a shell builtin paul@fullstack:~$ clear

A list and short summary of all 60 builtins can be found with bash -c help.

paul@fullstack:~$ bash -c help GNU bash, version 4.3.30(1)-release (x86_64-pc-linux-gnu) These shell commands are defined internally. Type `help' to see this list. Type `help name' to find out more about the function `name'. Use `info bash' to find out more about the shell in general. Use `man -k' or `info' to find out more about commands not in this list. A star (*) next to a name means that the command is disabled. job_spec [&] history [-c] [-d offset] [n] or hist> (( expression )) if COMMANDS; then COMMANDS; [ elif C> . filename [arguments] jobs [-lnprs] [jobspec ...] or jobs > : kill [-s sigspec | -n signum | -sigs> [ arg... ] let arg [arg ...] [[ expression ]] local [option] name[=value] ... alias [-p] [name[=value] ... ] logout [n] bg [job_spec ...] mapfile [-n count] [-O origin] [-s c> bind [-lpsvPSVX] [-m keymap] [-f file> popd [-n] [+N | -N] break [n] printf [-v var] format [arguments] builtin [shell-builtin [arg ...]] pushd [-n] [+N | -N | dir] caller [expr] pwd [-LP] case WORD in [PATTERN [| PATTERN]...)> read [-ers] [-a array] [-d delim] [-> cd [-L|[-P [-e]] [-@]] [dir] readarray [-n count] [-O origin] [-s> command [-pVv] command [arg ...] readonly [-aAf] [name[=value] ...] o> compgen [-abcdefgjksuv] [-o option] > return [n] complete [-abcdefgjksuv] [-pr] [-DE] > select NAME [in WORDS ... ;] do COMM> compopt [-o|+o option] [-DE] [name ..> set [-abefhkmnptuvxBCHP] [-o option-> continue [n] shift [n] coproc [NAME] command [redirections] shopt [-pqsu] [-o] [optname ...] declare [-aAfFgilnrtux] [-p] [name[=v> source filename [arguments] dirs [-clpv] [+N] [-N] suspend [-f] disown [-h] [-ar] [jobspec ...] test [expr] echo [-neE] [arg ...] time [-p] pipeline enable [-a] [-dnps] [-f filename] [na> times eval [arg ...] trap [-lp] [[arg] signal_spec ...] exec [-cl] [-a name] [command [argume> true exit [n] type [-afptP] name [name ...] export [-fn] [name[=value] ...] or ex> typeset [-aAfFgilrtux] [-p] name[=va> false ulimit [-SHabcdefilmnpqrstuvxT] [lim> fc [-e ename] [-lnr] [first] [last] o> umask [-p] [-S] [mode] fg [job_spec] unalias [-a] name [name ...] for NAME [in WORDS ... ] ; do COMMAND> unset [-f] [-v] [-n] [name ...] for (( exp1; exp2; exp3 )); do COMMAN> until COMMANDS; do COMMANDS; done function name { COMMANDS ; } or name > variables - Names and meanings of so> getopts optstring name [arg] wait [-n] [id ...] hash [-lr] [-p pathname] [-dt] [name > while COMMANDS; do COMMANDS; done help [-dms] [pattern ...] { COMMANDS ; } paul@fullstack:~$ clear

Please note, a few are required for beginners, Shift+PgUp, there's cd and pwd and Shift+PgDn to see exit and the one called help, which we'll cover next.

First, let's get context on that 60 number. My bare-bones Debian Linux distribution has about 1,000 commands total, found by listing all files in 4 bin, for binary, directories that hold programs and counting lines with wc.

paul@fullstack:~$ ls /bin /sbin /usr/bin /usr/sbin | wc -l 1074

Step 4 - How to Find Help

Finding help in general

Think of builtins as required to keep the computer in working order. The other 940 supplemental programs cover other purposes, like, whatis, clear and less. For most of those you would use --help for the short version.

paul@fullstack:~$ whatis --help Usage: whatis [OPTION...] KEYWORD... -d, --debug emit debugging messages -v, --verbose print verbose warning messages -r, --regex interpret each keyword as a regex -w, --wildcard the keyword(s) contain wildcards -l, --long do not trim output to terminal width -C, --config-file=FILE use this user configuration file -L, --locale=LOCALE define the locale for this search -m, --systems=SYSTEM use manual pages from other systems -M, --manpath=PATH set search path for manual pages to PATH -s, --sections=LIST, --section=LIST search only these sections (colon-separated) -?, --help give this help list --usage give a short usage message -V, --version print program version Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options.

And the man page for the long version of help (for whatis).

paul@fullstack:~$ man whatis
paul@fullstack:~$ man whatis WHATIS(1) Manual pager utils WHATIS(1) NAME whatis - display one-line manual page descriptions SYNOPSIS whatis [-dlv?V] [-r|-w] [-s list] [-m system[,...]] [-M path] [-L locale] [-C file] name ... DESCRIPTION Each manual page has a short description available within it. whatis searches the manual page names and displays the manual page descriptions of any name matched. name may contain wildcards (-w) or be a regular expression (-r). Using these options, it may be necessary to quote the name or escape (\) the special characters to stop the shell from interpreting them. index databases are used during the search, and are updated by the mandb program. Depending on your installation, this may be run by a periodic cron job, or may need to be run manually after new manual pages have been installed. To produce an old style text whatis database from the relative index database, issue the command: whatis -M manpath -w '*' | sort > manpath/whatis where manpath is a manual page hierarchy such as /usr/man. OPTIONS -d, --debug (102 lines trimmed) AUTHOR Wilf. (G.Wilford@ee.surrey.ac.uk). Fabrizio Polacco (fpolacco@debian.org). Colin Watson (cjwatson@debian.org). 2.7.0.2 2014-09-28 WHATIS(1)
How to find help on builtins

Okay, what about help on builtins? For the short version use the help command, a builtin used exclusively for help on builtins.

So using help on help works.

paul@fullstack:~$ help help help: help [-dms] [pattern ...] Display information about builtin commands. Displays brief summaries of builtin commands. If PATTERN is specified, gives detailed help on all commands matching PATTERN, otherwise the list of help topics is printed. Options: -d output short description for each topic -m display usage in pseudo-manpage format -s output only a short usage synopsis for each topic matching PATTERN Arguments: PATTERN Pattern specifiying a help topic Exit Status: Returns success unless PATTERN is not found or an invalid option is given.

What if you did a whatis or man on help?

paul@fullstack:~$ whatis help; man help help: nothing appropriate No manual entry for help paul@fullstack:~$ clear

See, nothing. So for a takeaway, if you can't find help on a command, first see if it's a builtin by using type, or with bash -c help and if it's there, use the help command.

For the long version, you'll need to access the daunting man page for bash that spans 5,000 lines.

paul@fullstack:~$ man bash | wc -l 5040 paul@fullstack:~$ man bash
BASH(1) General Commands Manual BASH(1) NAME bash - GNU Bourne-Again SHell SYNOPSIS bash [options] [command_string | file] COPYRIGHT Bash is Copyright (C) 1989-2013 by the Free Software Foundation, Inc. DESCRIPTION Bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file. Bash also incorporates useful features from the Korn and C shells (ksh and csh). Bash is intended to be a conformant implementation of the Shell and Utilities por tion of the IEEE POSIX specification (IEEE Standard 1003.1). Bash can be configured to be POSIX-conformant by default. OPTIONS All of the single-character shell options documented in the description of the set builtin command can be used as options when the shell is invoked. In addition, bash interprets the following options when it is invoked: -c If the -c option is present, then commands are read from the first non- option argument command_string. If there are arguments after the com mand_string, they are assigned to the positional parameters, starting with

And now for that time-saving trick, once here type the forward slash / and the term you want to look up so /builtin for example and Enter zooms to that line.

builtin command can be used as options when the shell is invoked. In addition, bash interprets the following options when it is invoked: -c If the -c option is present, then commands are read from the first non- option argument command_string. If there are arguments after the com‐ mand_string, they are assigned to the positional parameters, starting with $0. -i If the -i option is present, the shell is interactive. -l Make bash act as if it had been invoked as a login shell (see INVOCATION below). -r If the -r option is present, the shell becomes restricted (see RESTRICTED SHELL below). -s If the -s option is present, or if no arguments remain after option pro‐ cessing, then commands are read from the standard input. This option allows the positional parameters to be set when invoking an interactive shell. -D A list of all double-quoted strings preceded by $ is printed on the stan‐ dard output. These are the strings that are subject to language transla‐ tion when the current locale is not C or POSIX. This implies the -n option; no commands will be executed. [-+]O [shopt_option] shopt_option is one of the shell options accepted by the shopt builtin (see SHELL BUILTIN COMMANDS below). If shopt_option is present, -O sets the value of that option; +O unsets it. If shopt_option is not supplied, the names and values of the shell options accepted by shopt are printed on the standard output. If the invocation option is +O, the output is dis‐ played in a format that may be reused as input. -- A -- signals the end of options and disables further option processing.

The n key zooms to the next occurrence.

shopt_option is one of the shell options accepted by the shopt builtin (see SHELL BUILTIN COMMANDS below). If shopt_option is present, -O sets the value of that option; +O unsets it. If shopt_option is not supplied, the names and values of the shell options accepted by shopt are printed on the standard output. If the invocation option is +O, the output is dis played in a format that may be reused as input. -- A -- signals the end of options and disables further option processing. Any arguments after the -- are treated as filenames and arguments. An argument of - is equivalent to --. Bash also interprets a number of multi-character options. These options must appear on the command line before the single-character options to be recognized. --debugger Arrange for the debugger profile to be executed before the shell starts. Turns on extended debugging mode (see the description of the extdebug option to the shopt builtin below). --dump-po-strings Equivalent to -D, but the output is in the GNU gettext po (portable object) file format. --dump-strings Equivalent to -D. --help Display a usage message on standard output and exit successfully. --init-file file --rcfile file Execute commands from file instead of the system wide initialization file /etc/bash.bashrc and the standard personal initialization file ~/.bashrc if the shell is interactive (see INVOCATION below).

For homework, I suggest reviewing this (the instructions for how to navigate the command less which is used for man).

SUMMARY OF LESS COMMANDS Commands marked with * may be preceded by a number, N. Notes in parentheses indicate the behavior if N is given. A key preceded by a caret indicates the Ctrl key; thus ^K is ctrl-K. h H Display this help. q :q Q :Q ZZ Exit. --------------------------------------------------------------------------- MOVING e ^E j ^N CR * Forward one line (or N lines). y ^Y k ^K ^P * Backward one line (or N lines). f ^F ^V SPACE * Forward one window (or N lines). b ^B ESC-v * Backward one window (or N lines). z * Forward one window (and set window to N). w * Backward one window (and set window to N). ESC-SPACE * Forward one window, but don't stop at end-of-file. d ^D * Forward one half-window (and set half-window to N). u ^U * Backward one half-window (and set half-window to N). ESC-) RightArrow * Left one half screen width (or N positions). ESC-( LeftArrow * Right one half screen width (or N positions). F Forward forever; like "tail -f". r ^R ^L Repaint screen. R Repaint screen, discarding buffered input. --------------------------------------------------- (200 lines trimmed)

Step 5 - Next: Common Symbols and Characters in Linux

And if this is your first time here, and this whole things seems odd, Full Stack is an open-ended journey to knowledge in Data Science using a software stack that starts out looking like this.

Keep an eye on us, because we may cover something helpful for your journey.

The next video promises to answer questions on those mysterious Linux symbols, (like . / ~ ; > | # ~ ).

Have a nice day.


What's Next?

See what else you can learn for free at our YouTube Channel. For reminders follow @factorpad on Twitter and our good old fashioned no-spam email list.

Outline Back Tip Next

/ factorpad.com / tech / full-stack / bash-shell-builtins.html


bash shell builtins
shell builtins
bash builtins
linux bash
builtins in Linux
linux built-in commands
shell builtin commands
linux help command
linux builtins explained
linux type command
find help on builtins
linux tutorial

A newly-updated free resource. Connect and refer a friend today.