Navigating through the plethora of Linux and Docker commands can be overwhelming. Bash Completion offers a solution by providing autocomplete functionality, streamlining command-line operations.
For both Linux and Docker, remembering all available commands can be daunting, especially for newcomers to the platform. With numerous commands like systemctl and Docker’s extensive list, efficient recall becomes crucial.
By utilizing the Tab key, Bash Completion enhances command-line efficiency, suggesting relevant commands as you type. This feature is particularly useful when dealing with complex commands or unfamiliar syntax.
Although Bash Completion works seamlessly for Linux commands, additional configuration is required for Docker commands. Despite this, installing Bash Completion from standard Linux repositories is a straightforward process.
Bash Completion simplifies command-line interactions by providing autocomplete functionality for Linux and Docker commands. By leveraging this tool, users can navigate command syntax more efficiently, improving productivity and reducing errors.
Some distributions may have Bash Completion pre-installed. To verify, run the installation command, and your package manager will inform you if it’s already available.
For Debian/Ubuntu-based distributions:
sudo apt-get install bash-completion -y
For Fedora/Red Hat Enterprise Linux-based distributions:
sudo dnf install bash-completion -y
After installation, test the application by typing:
systemctl s
Press the Tab key twice to display all available subcommands for systemctl.
To enable Docker support in bash-completion, download the Docker complete file and copy it to the /etc/bash_completion.d/
directory.
sudo curl https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/bash/docker -o /etc/bash_completion.d/docker.sh
If you encounter a permissions error, execute the following command before retrying:
sudo -s
Then rerun the curl command.
Once the setup is complete, test bash-completion with Docker. For example:
docker i
Press Tab twice to view the available options, which will assist in recalling the desired command.
While Bash Completion is a valuable tool for displaying available subcommands, it does not assist with the various options associated with those subcommands.
For example, typing “docker ps” and pressing Tab twice won’t list out options like -a (or –all), -f (or –filter), –format, -n (or –last), -l (or –latest), –no-trunc, -q (or –quiet), -s (or –size). In such cases, referring to the manual page (man page) is recommended.
To access the manual page for a command, such as Docker’s “ps” subcommand, you can type:
man docker ps
Press Enter to view all available options for that command. This approach applies to most Docker subcommands. Simply type “man docker” followed by the subcommand of interest and press Enter to access comprehensive information.
Although Bash Completion streamlines Linux and Docker command-line usage by displaying available subcommands, referencing the manual page remains invaluable for exploring command options. With the vast array of Linux commands available, any assistance in simplifying usage is highly appreciated.