26

We know bash supports number of buitin commands like:

$ type type cd help command
type is a shell builtin
cd is a shell builtin
help is a shell builtin
command is a shell builtin

I want to get list of all available shell builtin commands. How do I do that by command-line?

21

You can use compgen -b from a bash shell to get a list of the shell's builtin commands.

| improve this answer | |
20

From the terminal type:

help

From help help:

Display information about builtin commands.
| improve this answer | |
  • Note that help lists shell keywords as well as shell builtins (and does not state explicitly which is which). – Eliah Kagan Sep 5 '19 at 0:09
13

Alternatively you can display with enable command: (Both @karel's and @steeldriver's answer works fine.)

enable -a | cut -d " " -f 2,3

If any builtin is disabled then it is shown with -n in out put.

Example output:

$ enable -a | cut -d " " -f 2,3
.
:
[
alias
bg
bind
break
builtin
caller
cd
command
compgen
complete
compopt
continue
declare
dirs
disown
echo
enable
eval
exec
exit
export
false
fc
fg
getopts
hash
help
history
jobs
kill
let
local
logout
mapfile
popd
printf
pushd
pwd
read
readarray
readonly
return
set
shift
shopt
source
suspend
test
times
trap
true
type
typeset
ulimit
umask
unalias
unset
wait
| improve this answer | |
2

For those who hate forking external binaries simply for data formatting / extraction:

while read -r _ cmd ; do echo $cmd ; done < <(enable -a)
| improve this answer | |
  • 1
    Why not simply a pipe instead of a FIFO redirection? enable -a | while read ... – David Foerster Sep 20 '16 at 22:56
  • 1
    That would also work. This is just a habit I am in so that any variable manipulation that I care to do inside the while loop is not executed inside a sub-shell. (Manipulating variables inside a sub-shell would mean that the changes are not persisted to outside the other end of the loop). – Nicola Worthington Apr 24 '17 at 9:45
2

Another way: man builtins

It displays the list of builtins at the top, then has all the details for each command below.

SYNOPSIS
       bash defines the following built-in commands: :, ., [, alias, bg, bind,
       break,  builtin,  case,  cd,  command,  compgen,  complete,   continue,
       declare,  dirs, disown, echo, enable, eval, exec, exit, export, fc, fg,
       getopts, hash, help, history, if, jobs, kill, let, local, logout, popd,
       printf,  pushd, pwd, read, readonly, return, set, shift, shopt, source,
       suspend, test, times, trap,  type,  typeset,  ulimit,  umask,  unalias,
       unset, until, wait, while.
| improve this answer | |
1

Just type in the Terminal:

man bash

This will open the manual of bash. Scroll down you will find SHELL BUILTIN COMMANDS. Here you can know about all the builtin commands and what they do. If you want the manual in a txt format, use this command

man bash > FILENAME.txt

Now you have the text file of bash manual.

| improve this answer | |
0

Well, bash is the default shell for ubuntu and the existing answers answered well.

For zshell, we can use enable command to list all builtins:

enable

and I get 103 builtin commands for my zshell:

enable | wc -l

Of course, we can also use enable to query all bash builtins:

enable | awk '{print $2}'
| improve this answer | |
  • Already suggest in this answer – Pandya Aug 17 at 3:01
  • @Pandya Can you please explain the difference between enable and enable -a? I got confused of them. I'm using zsh, and enable gives 103 builtin commands, while enable -a only gives 13 commands. – HaxtraZ Aug 17 at 3:04
  • @Pandya Let me give more detail: in zsh, enable -a | cut -d " " -f 2,3 gives 13 output, and many of them are not builtin comands, I think. e.g. -lF isn't, and -q' isn't. – HaxtraZ Aug 17 at 3:05
  • oh. I will investigate it and will inform you. – Pandya Aug 17 at 3:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.