The bash: service: command not found error is reported when root restarts the service in CentOS.

Source: Internet
Author: User
Tags centos iptables

Yezee user ssh to the server, then su to the root user, ready to restart the iptables service

Run the service command to restart the iptables service:

[Root @ www sysconfig] # service iptables restart

The bash: service: command not found error is returned.
Why are there no service commands? Then I searched the internet for an explanation from a foreign forum:

Http://www.linuxquestions.org/questions/linux-newbie-8/service-__-restart-bash-command-isnt-working-102136/

The su root format cannot be used to convert to root.

Need to use

[Yezee @ www sysconfig] $ su-root

Or

[Yezee @ www root] $ su-

Or

Directly su root and then write the absolute service path/sbin/service servicename start

To the root user, you can use the service.

In this way, the bash: service: command not found error will no longer occur.

As for why do we use the-symbol? Read the help of the su command.

[Root @ www ~] # Su-help
Usage: su [OPTION]… [-] [USER [ARG]…]
Change the valid tive user id and group id to that of USER.

-,-L,-login make the shell a login shell
-G-group = group specify the primary group
-G-supp-group = group specify a supplemental group
-C,-commmand = COMMAND pass a single COMMAND to the shell with-c
-Session-command = COMMAND pass a single COMMAND to the shell with-c
And do not create a new session
-F,-fast pass-f to the shell (for csh or tcsh)
-M,-preserve-environment do not reset environment variables
-P same as-m
-S,-shell = SHELL run SHELL if/etc/shells allows it
-Help display this help and exit
-Version output version information and exit

A mere-implies-l. If USER not given, assume root.

Report bugs to <bug-coreutils@gnu.org>.

This is actually the same effect as-or-l or-login.

-,-L,-login make the shell a login shell

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.