Bash autocomplete ( less typing )

dos2unix

Well-Known Member
Joined
May 3, 2019
Messages
3,525
Reaction score
3,285
Credits
31,524

Bash Autocomplete in Linux Using the Tab Key​

Bash autocomplete is a powerful feature in Linux that allows users to quickly complete commands, filenames, and directory names by pressing the Tab key. This feature can save time and reduce errors when typing long commands or paths.

How to Use Bash Autocomplete​

To use Bash autocomplete, simply start typing a command or filename and press the Tab key. Bash will attempt to complete the text based on the available options. If there are multiple possibilities, pressing Tab twice will display a list of possible completions.

For example, if you have a directory with the following files:

Code:
 file1.txt file2.txt file3.txt

Typing fi and pressing Tab will autocomplete to file, and pressing Tab again will show the list of files starting with file.

Case Sensitivity in Linux vs. Windows​

Linux is case-sensitive, meaning that File.txt and file.txt are considered different files. In contrast, Windows is generally case-insensitive, treating File.txt and file.txt as the same file. This difference can affect how autocomplete works in each operating system.

Example Directory Structure​

Let's create an example directory structure to demonstrate how autocomplete works with similar filenames:

Code:
 mkdir example_dir cd example_dir touch fileA1.txt fileA2.txt fileB1.txt fileB2.txt fileC1.txt fileC2.txt

In this directory, we have files with similar starting letters but different subsequent letters. Typing file and pressing Tab will autocomplete to file, and pressing Tab again will show the list of files starting with file.

Autocomplete with Similar Filenames​

Now, let's add a couple of files where the first six letters are the same:

Code:
 touch fileABC1.txt fileABC2.txt

With these files, typing fileAB and pressing Tab will autocomplete to fileABC, and pressing Tab again will show the list of files starting with fileABC.

Conclusion​

Bash autocomplete is a useful feature that can enhance your productivity in the Linux terminal. Understanding how case sensitivity works and how to navigate directories with similar filenames can help you make the most of this feature.
 


Members online


Top