A builtin command is a Linux/Unix command which is "built into a shell interpreter such as sh, ksh, bash, dash, csh etc". Thats where the name came from for these built-in commands. In other words we can say that these commands will always available in RAM so that accessing them is bit fast when compared to external commands which are stored on hard disk. There are many advantages for this type of commands. Below are some advantages.
When we keep frequently execute commands in RAM they will decrease time delay in accessing them from disks and improve performance. Built-in commands will solve this problem by loading them self into RAM when an Interpreter is loaded in to
Maintain set of commands at minimal shell
Sometimes there is high chance of system crash and you can not access anything on a machine. But if we still have shell access we can execute all builtin commands to do basic troubleshooting and recovery system.
How to list all built-in commands?
There are many ways we can list builtin commands. Commands like compgen and help will help us to list all available builtin commands for a particular shell.
[firstname.lastname@example.org ~]$ compgen -b
[email@example.com ~]$ help
We should make note that "builtin commands varies from shell to shell".
How to check if a Linux command is built-in or not?
To check if a command is external or internal command(built-in) we have to execute type command
[firstname.lastname@example.org ~]$ type cd
cd is a shell builtin
[email@example.com ~]$ type pwd
pwd is a shell builtin
[firstname.lastname@example.org ~]$ type ls
ls is aliased to `ls –color=auto'
[email@example.com ~]$ type whoami
whoami is /usr/bin/whoami
If you observe ls and whoami commands are not built-in commands.
How to find Linux built-in command location?
This is bit tricky questions. As said earlier builtin commands are built into the shell and they are not individual files which can be located in the system. So there is no location for built in commands and this is the reason you will get below error for some of the built-in commands when you try to locate them.
[firstname.lastname@example.org ~]$ which cd
/usr/bin/which: no cd in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/visplad/bin)
[email@example.com ~]$ which let
/usr/bin/which: no let in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/visplad/bin)
How to find size of built-in commands?
Again this is bit tricky. We can not find the size of individual built-in commands as they are part and parcel of your shell. To know the size of your shell just execute below command
[firstname.lastname@example.org ~]$ du -hs $(which bash)
Replace bash with your desired shell.
How to get help on built-in commands?
So the important question is how to get help on these built-in commands. When you try to execute man on these commands you will get below error
email@example.com:~$ man cd
No manual entry for cd
Then where we can get help on them?
There is special command to help you on this. The command to get more help on Linux/Unix built-in commands is help. To know about a command in detail just execute below command.
help -m cd
[firstname.lastname@example.org ~]$ help -m cd
cd – Change the shell working directory.
cd [-L|-P] [dir]
Change the shell working directory.
Change the current directory to DIR. The default DIR is the value of the
HOME shell variable.
The variable CDPATH defines the search path for the directory containing
DIR. Alternative directory names in CDPATH are separated by a colon (:).
A null directory name is the same as the current directory. If DIR begins
with a slash (/), then CDPATH is not used.
If the directory is not found, and the shell option `cdable_vars' is set,
the word is assumed to be a variable name. If that variable has a value,
it’s value is used for DIR.
-L force symbolic links to be followed
-P use the physical directory structure without following symbolic
The default is to follow symbolic links, as if `-L' were specified.
Returns 0 if the directory is changed; non-zero otherwise.
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
To get single line answer use -d option with help command.
[email@example.com ~]$ help -d cd
cd – Change the shell working directory.
To get simple command options use -s option.
[firstname.lastname@example.org ~]$ help -s cd
cd: cd [-L|-P] [dir]
Hope this helps to understand about built-in commands in Linux.
Latest posts by Surendra Anne (see all)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix- June 29, 2020
- FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018