While running the complete command on my gnome-terminal, it shows some commands.What are they? And what is the use of complete command?
$ complete
complete -F _minimal
complete -F _filedir_xspec oodraw
complete -F _filedir_xspec elinks
complete -F _filedir_xspec freeamp
complete -F _longopt split
complete -F _longopt sed
complete -F _longopt ld
complete -F _longopt grep
complete -F _service /etc/init.d/vboxweb-service
complete -F _service /etc/init.d/vboxballoonctrl-service
complete -F _service /etc/init.d/rc
complete -F _service /etc/init.d/nmbd
complete -F _service /etc/init.d/halt
complete -j -P '"%' -S '"' jobs
complete -d pushdList goes long, so i posted some of the them.
32 Answers
complete is a bash builtin function. So there is not a binary on the system. It handles how commands will be completed when pressing tab.
Example: if you type:
user@host:~$ pidof <tab><tab>...a list is appearing with all possible values for this command. In this case it means all running processes. See the output of the complete function:
user@host:~$ complete | grep pidof
complete -F _pgrep pidofThis means that the function _pgrep (-F) is executed when tabbing the command pidof. The definition of this function is in /etc/bash_completion.d/procps.
Another example: if you type:
user@host:~$ cd /usr/<tab><tab>
bin/ games/ include/ lib/ lib32/ local/ sbin/ share/ src/...you see the list of folders you can cd to under /usr/. Which function is executed? greping the complete function (as above) tells us it's the funtction _cd in /etc/bash_completion.
Do it yourself: You have a program/script called /bin/myprog and you want that if you execute it as follows
user@host:~$ myprog /home/user/<tab><tab>...it should only list folders, not files. So extend your bash completion with the following command:
user@host:~$ complete -F _cd myprogThat's it. You can also write own functions to complete custom things, for example complete only specific files or numbers or lists of static values...
1complete is a bash command used to perform the auto-complete action when the user hit the TAB key in a terminal.
Calling just complete will list all the functions registered for auto-completion of commands or services options.
From the bash man pages:
complete: complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [name ...] Specify how arguments are to be completed by Readline. For each NAME, specify how arguments are to be completed. If no options are supplied, existing completion specifications are printed in a way that allows them to be reused as input. Options: -p print existing completion specifications in a reusable format -r remove a completion specification for each NAME, or, if no NAMEs are supplied, all completion specifications -D apply the completions and actions as the default for commands without any specific completion defined -E apply the completions and actions to "empty" commands -- completion attempted on a blank line When completion is attempted, the actions are applied in the order the uppercase-letter options are listed above. The -D option takes precedence over -E. Exit Status: Returns success unless an invalid option is supplied or an error occurs.Check /usr/share/bash-completion/bash_completion to see the default completions that come with bash.
Visit for a full tutorial about this command.