Linux for Starters

Linux for Starters: Your Guide to Linux – Get Started with the Terminal – Part 9

Shell Builtins

A builtin is a command contained within the Bash tool set. They execute faster than external commands and have direct access to the shell internals.

One of the shell builtins is compgen. It lists all the shell builtins in bash when run with the -b option.

$ compgen -b

We’ve compiled a table explaining all the shell builtins in the Appendix, but here’s some that will be particularly interesting to newcomers to Linux.


. (period)

The .  is a symbol that, in the context of file management, refers to the current directory. But in terms of the shell, it refers to read and execute commands from the filename argument in the current shell context.

The period lets you run commands from a directory that’s not in your PATH. PATH is an environmental variable that tells the shell which directories to search for executable files in response to commands issued by a user.


cd (change directory)

cd is one of the most important and commonly used shell builtins. It lets us change directories so that we can navigate around the filesystem. Here’s a few simple cd commands we can issue.

Let’s move from any working directory to our home directory with the command:

$ cd ~

Move up a directory with the command:

$ cd ..

To move from the current working directory to /etc type:

$ cd /etc

We can also specify local directories by removing the / character. For example, if the current directory is /usr/local we can move to  /usr/local/bin with the command:

$ cd bin

Pressing the tab key will autocomplete a path. Where there’s more than one matching directory, pressing tab twice will list the available matches. For example, if our working directory is /usr/local, we can type type $ cd s and press tab twice. This action lists the sub-directories that start with the letter s.


export

The export command exports a variable or function to the environment of all the child processes running in the current shell.

To view all exported variables on the current shell, use the -p flag.

Linux for Starters - export


kill

kill is a shell builtin for two reasons: it allows job IDs to be used instead of process IDs, and allows processes to be killed if the limit on processes that you can create is reached.


bg and fg

The fg command switches a job running in the background into the foreground. The bg command restarts a suspended job, and runs it in the background. If no job number is specified, then the fg or bg command acts upon the currently running job.


history

Bash provides access to the list of commands you previously issued, which is known as your command history.

This feature makes it easy to repeat commands, substitute text, manipulate arguments, and fix typos in your previous commands quickly.


alias

This command displays aliases. We’ll cover aliases on the next page.


echo

The echo command does one simple job: it prints to the output an expression or variable.

The image below shows the output of the environment variable $PATH as relayed by echo. Each of the path directories is separated by a colon.

Linux for Starters - echo


Getting Help about the Shell Builtins

Each of the shell builtins are documented. Append --help to the shell builtin command to learn more about them and their options. Here’s an example for the cd builtin.

$ cd --help

Linux for Starters - cd help

Page 3 – Aliases

Pages in this article:
Page 1 – Types of Commands
Page 2 – Shell Builtins
Page 3 – Aliases
Page 4 – External Commands
Page 5 – Navigate the shell efficiently
Page 6 – Appendix – Explanation of Shell Builtins


All articles in this series:

Linux For Starters: Your Guide to Linux
Part 1What is Linux? Why use Linux? What do I need?
Part 2Choose a Linux distribution meeting your specific needs and requirements.
Part 3Make a bootable Ubuntu USB stick in Windows.
Part 4We show you how to install Ubuntu 21.04 on your hard disk.
Part 5Things to do after installing Ubuntu.
Part 6Navigating your way around the Desktop.
Part 7Updating the system, install new software.
Part 8Open source replacements for proprietary Windows desktop software.
Part 9Get started with the power and flexibility of the terminal.
Part 10We cover the basics of files and permissions.
Part 11Getting help from your system.
Part 12Learn all about the file system.
Part 13Manipulating files from the shell.
Part 14Maintain your system with these simple tips.
Part 15Managing users on your system.
Part 16Explore different desktops to GNOME 3.
Part 17Gaming on Linux.
Part 18Protect your privacy with this guide.
Part 19Access the Windows desktop from Linux using a remote desktop client.
Part 20Set up a virtual machine running Ubuntu as the host and openSUSE as the guest.
Part 21Wine lets you run Windows programs on Linux without emulation.
Share this article

Share your Thoughts

This site uses Akismet to reduce spam. Learn how your comment data is processed.