Linux shutdown, reboot, halt, init, and haltinit

Source: Internet
Author: User

Linux shutdown, reboot, halt, init, and haltinit

Command Overview

Shutdown, poweroff, reboot, halt, and init can all be shut down for general usage.

/Sbin/halt [-n] [-w] [-d] [-f] [-I] [-p] [-h]
/Sbin/reboot [-n] [-w] [-d] [-f] [-I]
/Sbin/poweroff [-n] [-w] [-d] [-f] [-I] [-h]

[Root @ linux ~] $ Reboot -- h
Usage: reboot [-n] [-w] [-d] [-f] [-h] [-I]
-N: not synchronized before stopping the system
-W: Write only the wtmp reboot record and exit.
-D: Do not write the wtmp record
-F: forced shutdown or restart
-H: Keep the hard disk in standalone Mode
-I: Disable all network interfaces.


Shutdown Process

1. Refresh the hard disk cache:
2. Record restart events: (/var/run/utmp,/var/log/wtmp)
3. Kill all processes:
4. Restart the machine:


Shutdown example

# Shutdown-h now # shutdown immediately
# Shutdown-h 02:30 'halt' # Shut Down at. Pay attention to the local time.
# Halt-p # immediate shutdown
# Init 0 # immediately switch the system running level to 0, that is, shutdown
# Shutdown now # Switch to single-user mode (when no option is added)


Restart example

# Shutdown-k now 'reboot' # send a warning message, but it does not actually shut down.
# Shutdown-t5-r now # restart immediately, but the delay between the warning and the deletion process is 5 seconds.
# Init 6 # immediately switch the system running level to 6, that is, restart
# Shutdown-r + 10 'reboot' # restart after 10 minutes
# Shutdown-c # cancel the previous shutdown command
# Shutdown-r now # restart immediately


Shutdown preparation

Linux is no better than Windows. If it cannot be shut down normally, it may cause file system damage because it is too late to write data back to a file. Therefore, pay attention to the following before shutdown:

1. Observe the system status

  • Use the who command to view online users
  • Run the netstat-a command to check the online network status.
  • Run the ps aux command to view the background execution program.

2. Notify online users # shutdown-k now 'System will reboot in 30 minutes! '

3. Use the correct command # first, determine whether to shut down or restart, and pay attention to parameters.

4. Pay attention to data synchronization # Use sync data synchronization to write data to Disks


Other Instructions

1. View restart records

# Last reboot


2. Remotely start the machine

# Ssh root @ server/sbin/reboot
# Ssh root@192.168.0.1/sbin/shutdown-r now


Linux shutdown command details

Linux shutdown Commands include shutdown, halt, reboot, and init. Shutdown is a safe method to shut down. You can notify all currently logged-on users before shutting down and prevent them from logging on. you can safely shut down background processes. You can use many parameters to configure specific functions. Halt: the starting function is equivalent to shutdown-h. It kills the application process and executes the sync system call. After some operations on the file system are completed, the kernel reboot will be stopped. The starting function is similar to halt, it only restarts after shutdown. Init: The init process is the ancestor of all processes. Its Process number is always 1. You can send a signal to the init process to shut down the process. shutdown is the implementation method. Basic commands for linux 1. exit: This command exits the system, but does not shut down. There are many jobs in linux. When you wait, it is equivalent to a job. When you wait, the job stops, but other jobs are still running, only shutdown is required.
2. date: display the current date
Format date: date + % y/% m/% d
3. cal: Display calendar
Format the calendar: cal [month] [year]
4. bc: built-in Calculator
5. man: Help! Similar to info
Man [command]
6. shutdown: shutdown.
Shutdown-t sec: shutdown-t shutdown 10 seconds
Shutdown-k message: shutdown-k I will shutdown is not really SHUTDOWN, just send a message I WILL shutdown
Shutdown-c cancels the shutdown command that is currently being executed
Shutdown-h time: shutdown-h 20:20 stop the system service, shutdown at 20:20
Shutdown-r time: shutdown-r now stop the system service, and then reboot
7. reboot: restart, and shutdown-r now
8. Directory File Permissions
Chgrp groupname file/directory: chgrp uranus1 a. Change the group of file a to uranus1.
Chmod xyz file/directory: chmod 777 a. Change the permission of file a to-rwxrwxrwx.
Chown user file/directory: chown uranus1 a. Change the owner of file a to uranus1.
Default permissions for umask files or directories
Umask: View
Umask xyz: Set

9. cd [relative or absolute path]
10. pwd displays the current path
11. Create/delete a directory by mkdir/rmdir
12. ls displays the file name and attributes.
Ls-a lists all files (together with hidden documents)
Ls-l detailed list
Ls-s sort by file size
13. Copy cp [souce] [object]
Cp-d
Cp-r allows directory Replication
Cp-s is used as the connection file, which has the same function as ln.
Cp-u will be copied only when the source file is new
14. rm [file name] delete an object
Rm-I user confirmation
Rm-r cyclic Deletion
Rm-f force Delete
15. mv [souce] [object] mobile
16. View File Content
Cat [file] viewing File Content
The last line of tac [file] is displayed... the remaining full text>

What command does linux use to shut down? What are the parameters? How to use it?

Common shutdown and restart commands in Linux include shutdown, halt, reboot, and init, which can be used for shutdown and restart. However, the internal working process of each command is different, next we will introduce them one by one.

1. shutdown

The shutdown command is used to safely shut down the Linux system. It is very dangerous for some users to disable Linux by directly disconnecting the power supply. Because Linux and Windows run many processes in the background, forced shutdown may lead to data loss in the process, making the system unstable and even damaging hardware devices.

When the shutdown command is executed, the system notifies all logged-on users that the system will be shut down and the login Command will be frozen. That is, new users cannot log on to the system. You can use the shutdown command to shut down the system directly, delay the specified time before shutting down the system, and restart the system. If the system is shut down after a specified delay, the user can have time to store the files being processed and to close the opened programs.

Some parameters of the shutdown command are as follows:

[-T] specifies how long the system will be shut down

[-R] restart the system

[-K] does not actually shut down, but sends a warning signal to every logged-on user.

[-H] Shut down the system (halt)

The job of the shutdown command is to send a signal to the init program and require it to switch the Runlevel of the system ). The system running level includes:

0: Shut down the system

1: in single-user mode, if the-h or-r parameter is not specified for the shutdown command, the system will switch to this running level by default.

2: multi-user mode (NFS not supported)

3: multi-user mode (supporting NFS), which is usually used

5: multi-user mode (GUI Mode)

6. restart the system.

2. halt

Halt is the simplest shutdown command. It actually calls the shutdown-h command. When halt is executed, the application process is killed. After the file system writes, the kernel is stopped.

Some parameters of the halt command are as follows:

[-F] Force shutdown or restart without calling shutdown

[-I] disable all network interfaces before shutting down or restarting

[-P] poweroff is called upon shutdown. This option is the default option.

3. reboot

The reboot process is similar to that of halt. Its function is to restart and halt is to shut down. Its parameters are similar to those of halt.

4. init

Init is the ancestor of all processes, and its Process number is always 1. Init is used to switch the running level of the system. The switchover is completed immediately. The init 0 command is used to immediately switch the system running level to 0, that is, shutdown. The init 6 command is used to switch the system running level to 6, that is, restart.
Reference: hi.baidu.com/...6.html

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.