In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to use command line completion in Linux", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to use command line completion in Linux" this article.
In Linux, when you type a command and press the TAB key twice, all available commands that begin with your input characters are listed. This is nothing new. Maybe you already know. This feature is called command-line completion bash completion. By default, the bash command line automatically completes the file or directory name. However, we can enhance the bash command completion and take it to new heights with the complete command.
This tutorial shows how we can use the programmable command line completion (programmable completion) to apply automatic completion to options or command line arguments.
For example, if you press the TAB button twice after entering the write command, the autocomplete feature provides a list of users available to perform write operations.
$write [TAB] [TAB] bala rajjason randyjohn ritumayla thomasnisha www-data
In the following example, you can display the available hostnames for the telnet command:
$telnet [TAB] [TAB] localhost dev-db fileserver
For programmable command completion to work on your terminal, you only need to execute / etc/bash_completion as follows:
#. / etc/bash_completion
You can also uncomment the following in / etc/bash.bashrc (from the Ubuntu Linux 13.04system) so that you don't have to execute the above command:
# enable bash completion in interactive shellsif! Shopt-oq posix; then if [- f / usr/share/bash-completion/bash_completion]; then. / usr/share/bash-completion/bash_completion elif [- f / etc/bash_completion]; then. / etc/bash_completion fifi
If you don't find the code or the / etc/bash_completion file, you just need to install the bash_completion package by using the apt-get command.
1. View existing command line completion
After enabling the programmable command line completion, there are already some well-defined command completion features. The complete command is used to define command line completion.
To view the existing command line completion, use the complete command as follows:
Complete-p | less
The-p option in the above example is optional.
two。 List the standard completion features in bash
By default, Bash provides the following standard completion features for Linux users.
◆ variable completion
◆ user name completion
◆ hostname completion
◆ path completion
◆ filename completion
We discussed this in the previous bash standard completion.
3. Define a command name completion
The-c option allows you to use all available commands as completion parameters for a command. In the following example, a completion is defined for the which command (LCTT translation note: when you double-click TAB, you can list all command names as complicable arguments).
$complete-c which $which [TAB] [TAB] Display all 2116 possibilities? (y or n)
As above, if you press'ycommands, all the command names will be listed.
4. Define a directory completion
With the option-d, you can define a completion parameter that contains only the directory name. In the following example, the completion is defined for the ls command.
$lscountfiles.sh dir1/ dir2/ dir3/ $complete-d ls $ls [TAB] [TAB] dir1/ dir2/ dir3/
As above, pressing TAB together will only show the directory name.
5. Define a background task name completion
The completion function can also take the task name as the completion parameter. The option-j can define the task name as a parameter passed to the command, as follows:
$jobs [1]-Stopped cat [2] + Stopped sed 'p' $complete-j. / list_job_attrib.sh $. / list_job_attrib.sh [TAB] [TAB] cat sed
For background tasks, you can refer to the examples in Linux background tasks to learn how to manage background tasks.
6. Completion with prefix and suffix
The completion function can define prefixes and suffixes for the actual completion. In the following example, prefixes and suffixes for the completion of the content are defined for list_job_attrib.sh.
$jobs [1] + Stopped cat $complete-P'">'- S 'cat
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.