How to Ignore Case When Using Tab Completion in the Linux Terminal

techsquadsllc

The command line in Linux is case sensitive. When you use tab completion to quickly change or list directories on the command line, you must match the case of the directory names. However, there is a way to make tab completion case insensitive.
Tab completion makes it quicker and easier to enter directories names on the command line. You can simply start typing the beginning of the directory name at the prompt and then press Tab to have the rest of the directory name automatically entered. For example, to change to the Documents directory, simply start typing cd Docu and then press Tab. It will autocomplete to cd Documents/ .
You can make this feature case insensitive by adding a setting to Linux’s .inputrc file. This file handles keyboard mappings for specific situations on the command line (or bash shell), and lets you customize the behavior of the command line. It’s very easy to add this setting and we’ll show you how.
There are two .inputrc files: a global one that applies to all users on the system ( /etc/.inputrc), and a local one in the current user’s home directory that applies only to that user ( ~/.inputrc). The ~ character represents the home directory, such as /home/lori/. The local .inputrc file overrides the global one, which means that any settings you add to the local file will be used despite what’s in the global file. We’re going to add the case insensitive setting to our local account in our example, but you can do it either way.
We’re going to use a text editor called gedit to add the setting to the .inputrc file. Press Ctrl+Alt+T to open the Terminal. Then, to change the local .inputrc file, type the following command at the prompt and press Enter.
gksu gedit ~/.inputrc
If you want to change the global .inputrc file, type the following command instead.
gksu gedit /etc/.inputrc
If you don’t have an .inputrc file, this command will create one in your home directory or /etc directory automatically.
techsquadsllc
A dialog box displays asking for your password, so enter the password you use to log in to your account and click “OK”.
techsquadsllc
The .inputrc file may be empty, and that’s fine. To have tab completion ignore case, add the following line to the file:
set completion-ignore-case on
Click “Save”.
techsquadsllc
To close gedit, click the “X” button in the upper-left corner.
techsquadsllc
The setting you just added to the .inputrc file will not affect the current Terminal window session. You must close the Terminal window and open it again for the change to take affect. So, type exit at the prompt and press Enter or click the “X” button in the upper-left corner of the window.
NOTE: You may see some warnings display, as shown below, but they don’t affect what we’re doing with the file.
techsquadsllc
Now, for example, when you type cd docu and press Tab…
techsquadsllc
…tab completion will work even though the case didn’t match the directory name.
techsquadsllc
If you want to go back to the default case sensitive setting for tab completion, simply open the same .inputrc file you added the setting to, delete the line you added, and save and close the file. Remember to close the Terminal window and reopen it after changing the .inputrc file.
Previous
Next Post »