If you fine-tune your Bash-shell behavior with
shopt, you can control over 50 settings. We show you how to customize your Linux system exactly the way you want it.
shopt built-in is part of all versions of the Bash shell, so there is no need to install anything. The number of available options in
shopt has increased steadily over the years. So the older version of Bash you have, the shorter the list
shopt options will be.
If something does not seem to work on your machine, check
man sidebar for Bash and check that the option is available in your version of
We cover everyone
shopt below. We also describe how to use it and share some examples. From there, you can check out the Bash man page or the GNU Bash Reference Manual to see if any of these options sound useful or appealing.
shopt options are enabled by default and form part of Bash̵
shoptoptions as a short-term change to Bash. It then returns to standard behavior when you close the shell.
But if you want a change in behavior to be available when you start a Bash shell, you can make the changes permanent.
There are 53
shopt alternative. If you use
shopt command without any options, it lists these. If we move the exit through
wc command, it will count lines, words, and characters for us. Because everyone
shopt the option is on its own row, the number of rows is the number of options.
We write the following:
shopt | wc
To see all the alternatives, we can guide the exit through
column command to display the option names in columns, or we can lead it to
We write the following:
shopt | column
Find shopt in Linux Manual
The section that discusses
shopt and its options can be found in the Bash section of the Linux manual. The Bash section is over 6000 lines long. You will find the description of
shopt with a lot of scrolling, or you can just search for it in the manual.
To do so, open the manual in the Bash section:
Press in the manual
/ to start a search. Type the following, and then press Enter:
shoptAlternative sections will be displayed in
RELATED: How to use Linux’s man Command: Hidden Secrets and Basics
Set and disable options
To set and deselect
shopt options, use the following commands:
- -s: Set or activate.
- -u: Disabled or disabled.
Since some options are enabled by default, it is also convenient to check which options are on. You can do it with
-u options without using an option name. This causes
shopt to list the options that are on and off.
Write the following:
shopt -u | column
You can use one
shopt option without
-u commands to view the on or off state of each option.
For example, we can write the following to check the setting for
We can write the following to set to:
shopt -s histverify
Then we can write the following to check it again:
histverify the option changes how an aspect of
history the command works. Usually, if you ask
history to repeat a command by referring to it as a number, such as
!245, the command is retrieved from the command history and executed immediately.
If you prefer to review a command to make sure it is what you expected and edit it, type the following if necessary to set
shopt histverify opportunity to:
The command is retrieved and presented on the command line. You can either delete, edit or execute it by pressing Enter.
RELATED: How to use the history command on Linux
autocd option is enabled, if you type the name of a directory on the command line and press Enter it will be treated as if you typed
cd in front of it.
We write the following to turn on
shopt -s autocd
Then we write the name of a directory:
cdspell the option is enabled, Bash will automatically correct simple spelling and typing errors in directory names.
We write the following to set
shopt -s cdspell
To try to switch to a lowercase letter that should have an uppercase letter, we write the following:
Then we can write the following to try a directory name with an extra “t” in its name:
Bash changes in each directory, regardless of spelling errors.
The xpg_echo option
xpg_echo option is enabled, the eco command will follow avoided characters, such as
n for new line and
t for horizontal tab.
First, we write the following to make sure the option is set:
shopt -s xpg_echo
We then bring
n in a string we are to pass to
echo "This is line onenThis is line two"
The fleeting new line character forces a line break in the output.
This gives the same behavior as
-e (enables interpretation of flight)
echo alternative, however
xpg_echo let it be the default action.
RELATED: How to use Echo Command on Linux
dotglob the option should be treated with some caution. It allows files and directories that start with a period (
.) to be included in name extensions or “globbing”. These are called “dot files” or “dot directories” and are usually hidden. The
dotglob the option ignores the dot at the beginning of their name.
First, we’ll search for files or directories ending in “geek” by typing the following:
A file is found and listed. Then we turn on
dotglob by writing the following:
shopt -s dotglob
We issue the same thing
ls command to search for files and directories ending in “geek”:
This time, two files are found and listed, one of which is a point file. You have to be careful
mv when you have
dotglob the option is on.
The Nocaseglob option
nocaseglob the option is similar
dotglob options, except
nocaseglob Causes differences in uppercase and lowercase letters in file names and directories to be ignored in name extensions.
We write the following to look for files or directories that begin with “how”:
A file is found and listed. We write the following to turn on
shopt -s nocaseglob
Then we repeat
Two files are found, one of which contains capital letters.
Make changes permanent
The changes we’ve made will only last until we close the current Bash shell. To make them permanent over different shell sessions, we need to add them to our “.bashrc” file.
Type the following command in your home directory to open the “.bashrc” file in the Gedit graphic text editor (or modify it to use your preferred editor):
gedit the editor opens with the “.bashrc” file loaded. You’ll see some
shopt records are already in it.
You can add your own
shopt options here as well. Once you have added them, save the changes and close the editor. Now, when you open a new Bash shell, your options will be set for you.
Options as far as the eye can see
shopt The command has many options, but you do not have to deal with them all at once, if ever. Since there are so many, there are probably some who will not interest you.
For example, there is a bunch that forces Bash to work in ways that are compatible with specific, older versions. It may be useful for someone, but it’s a pretty niche case.
You can view the Bash man page or the GNU Bash Reference Manual. Decide which options will make a difference for you and then experiment with them. Just be careful with options that affect how file and directory names are expanded. Try them with a benign command, like
lsuntil you are comfortable with them.