1. Overview

In this tutorial, we’ll talk about the .inputrc file. We’ll cover what it is, what we can use it for, and how it differs from other configuration files such as .bashrc.

For example, there are settings and options in .inputrc that we can also specify in other configuration files. However, based on the file where we specify these settings, they will affect different applications.

2. The .inputrc File and readline

First, let’s start by describing what the .inputrc file is. The file .inputrc is a configuration file in Unix that deals with keyboard mapping and is used as a startup file by readline. Thus, it needs to contain the configuration that concerns this library.

The question now might be: what is readline? The GNU readline library is one that other applications use to interact with a command line. It provides functions such as scrollback, line editing, text cursor movement, clipboard, and tab completion.

readline supports both vi and emacs editing modes, so we can configure (via the .inputrc file) how readline interprets the keyboard inputs. Moreover, the readline library also includes a history functionality. This way, we keep a list of the command lines that we’ve entered previously. We can go back (and even edit) those lines.

Since readline is a library that we can find in many applications, one of its main advantages is we can have the same behavior in all those applications.

Many common applications use readline: shells (like bash), programming language interpreters for languages such as Python, and other interactive tools in the command line. For example, the command line calculator bc and the command-line FTP client lftp also use readline.

With the .inputrc file, we can configure the behavior of all these applications that use readline altogether. It’s convenient to have this for consistent behavior in the applications we use in the command line.

3. Uses and Example Configurations for the .inputrc File

As with many other configuration files, we can find the default .inputrc file in the /etc/ directory:

4. The .inputrc File Compared to Other Configuration Files

In Linux systems, there are plenty of configuration files that we can use to tweak the behavior of tools. We commonly find .bashrc, .bash-profile, .profile, and also .inputrc.

The main difference between the .inputrc file and these other configuration files is that .inputrc modifies the behavior of the readline library. These settings certainly impact all the applications that use readline.

For example, when we start bash, it’ll initialize the history and other settings for the readline library from the .inputrc file and then read other files (such as .bashrc) for settings that are specific to bash.

We can run bash without the readline support to test the settings of bash independently:

$ bash --noediting

Since there is an overlap of functionalities between readline and bash, there’s also an overlap in the settings. We can specify settings in the .inputrc and the .bashrc files that look similar, but they affect different tools. The*.inputrc* file controls all readline applications, while .bashrc controls only bash.

Let’s consider the length of the command history. Both readline and bash keep a history of the previously run commands. This setting is known as HISTSIZE in bash and as history-size in .inputrc.

If we only provide HISTSIZE, we’ll only change the settings of bash. When we specify a value of history-size, we’ll change the settings of all applications that use readline (including bash!). Finally, if we specify both HISTIZE and history-size, the settings of the readline library will override the setting of bash.

5. Conclusion

In this article, we’ve talked about the .inputrc file and how the readline library and all the applications that rely on this library use the configuration file .inputrc. We’ve seen some examples of commands that we may want in this file. Finally, we’ve discussed the differences between the .inputrc file and other configuration files such as .bashrc.