In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "what are the command completion skills in Linux". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "what are the command completion skills in Linux".
By default, the bash command line automatically completes the file or directory name. However, we can make the bash command line completion perform more operations, and by completing the command, we can make it the next brilliant thing.
This tutorial shows how we use the programmable command-line completion (programmable completion) to apply auto-completion to options or command-line arguments.
For example, after entering the write command, if you press the TAB button twice, the autocomplete function will provide a list of write operations.
The code is as follows:
$write [TAB] [TAB]
Bala raj
Jason randy
John ritu
Mayla thomas
Nisha www-data
In the following example, entering the telnet command will show that the hostname is available:
The code is as follows:
$telnet [TAB] [TAB]
Localhost dev-db fileserver
For programmable command completion to work on your terminal, you just need to execute / etc/bash_completion, as shown below:
The code is as follows:
#. / etc/bash_completion
You can also uncomment under / etc/bash.bashrc (for Ubuntu Linux 13.04systems) so that you don't have to execute the above command
The code is as follows:
Enable bash completion in interactive shells
If! 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
Fi
Fi
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 bash completion commands
By enabling the programmable bash command line completion function, you can define a set of bash completion commands. Command line completion can be used to define bash completion commands.
Take a look at the existing bash completion feature, using the complete command, as follows:
The code is as follows:
Complete-p | less
Option-p is optional.
2. List of standard complements in Bash
Bash provides the following standard completion commands by default for linux users.
Variable name completion (Variablename completion)
User name completion (Username completion)
Hostname completion (Hostname completion)
Path path completion (Pathname completion)
File name completion (Filename completion)
3. Define the completion command for the get command
Use the-c argument to define a completion command to get a list of available commands. In the following example, a completion command is defined for the which command
The code is as follows:
$complete-c which
$which [TAB] [TAB]
Display all 2116 possibilities? (y or n)
As you can see above, if you press "y", all commands will be displayed.
4. Complete the command to get the directory definition
Using the parameter d, define a completion command that gets only the directory name. In the following example, the completion command for ls is defined
The code is as follows:
$ls
Countfiles.sh dir1/ dir2/ dir3/
$complete-d ls
$ls [TAB] [TAB]
Dir1/ dir2/ dir3/
As you can see above, press TAB twice in a row to see the directory name.
5. Get the completion command to get the background job name
It is allowed to get the job name as a parameter by using the complete command. Parameter j is used to pass the job name as an argument to the command line, as shown below:
The code is as follows:
$jobs
[1]-Stopped cat
[2] + Stopped sed 'p'
$complete-j. / list_job_attrib.sh
$. / list_job_attrib.sh [TAB] [TAB]
Cat sed
To learn more about background tasks, you can use these cases to learn how to manage Linux background tasks.
6. Use prefix and suffix completion commands
Completion commands can be defined by prefixes (added after) and suffixes (added after). In the following example, prefixes and suffixes are defined in list_job_attrib.sh.
The code is as follows:
$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.