Redhat/Fedora: Auto Complete for the “service” command
In Redhat, Fedora, or Centos Linux, you’re required to type command such as “service sshd start” and the main problem is NO auto complete for service command by default. Yes I admitted I’m lazy guy!
So how to set AUTO COMPLETE “service” command on Redhat/Centos? Read Below.
Type:
complete -W "$(ls /etc/init.d/)" service
* complete : the command complete sets up tab completion
* -W : this option creates a word list for completion
* “$(ls /etc/init.d/)” : out word list is made up of the output of the command ls /etc/init.d/
* service : this then sets up the configured completion for the command service
So when you issue a command “service n” and press tab, you should be able to see any services that start with the word “n” within /etc/init.d/ folder such as “ntpd”, “network”, “nfs” and etc.
Enjoy!








A similar command is useful for chkconfig:
complete -W “$(ls /etc/init.d/)” chkconfig