Common CentOS commands: bc, man, shutdown
This article mainly records the usage and meaning of some Linux commands, such as bc, man, and shutdown.
I. bc (a simple calculator in Linux)
In windows, a calculator tool is provided. We can use it for various computations. in Linux, there is also a simple calculator function, we can use the bc command for some simple calculations.
[Root @ xiaoluo ~] # Bcbc 1.06.95Copyright 1991-1994,199 7, 1998,200 0, 2004,200 6 Free Software Foundation, Inc. this is free software with absolutely no warranty. for details type 'warranty '. -- >>> here we enter some operations
Now we have entered the work environment of the bc simple calculator. Under this simple calculator, we can perform the following simple operations:
+ Addition,-subtraction, * multiplication,/division, ^ exponent, % Remainder
For example:
12 + 15 + 123912*56010 ^ 210010% 3110/33 --> Why is 3 only displayed here? This is because bc outputs Integers by default. If we want to output decimal places, we also need to execute a scale command, for example, scale = 3, which indicates output of three decimal places.
Scale = 310/33. 333 quit-> exit the current bc calculator command
This simple calculator function is like this. Through the bc command, we can perform some simple data operations in Linux.
2. man command
Linux has many commands. you can press the [Tab] key twice in bash to view the number of commands in Linux, for example:
[root@xiaoluo ~]# Display all 4221 possibilities? (y or n)
We can see that there are a total of 4221 commands in my installed CentOS6.4 system. Do we need to remember so many commands? Of course, it cannot be so silly. Just like java APIs, we cannot remember so many classes and methods, therefore, if you need a command, you only need to google it. When we get a command and how to use it, we need to ask man. We have such a popular phrase in Linux. If we do not know the specific usage of a command, we need to find a man ). Of course, this man is short for manual (operation instructions). For example, to view the usage of the date command, you can enter the man date command for viewing:
[Root @ xiaoluo ~] # Man dateDATE (1) User Commands DATE (1) NAME date-print or set the system date and timeSYNOPSIS date [OPTION]... [+ FORMAT] date [-u | -- utc | -- universal] [MMDDhhmm [[CC] YY] [. ss] DESCRIPTION Display the current time in the given FORMAT, or set the system date. -d, -- date = STRING display time described by STRING, not 'right'-f, -- file = DATEFILE like -- date once for each line of DATEFILE-r, -- reference = FILE display the last modification time of FILE-R, -- rfc-2822 output date and time in RFC 2822 format. example: Mon, 07 Aug ...................................... ........ A few hundred words are omitted here .................................... ................. date string The -- date = STRING is a mostly free format human readable date string such as "Sun, 29 Feb 2004 16:21:42-0800" or "16:21:42" or even "next Thursday ". A date string may contain in items indicating cal-endar date, time of day, time zone, day of week, relative time, rela-tive date, and numbers. an empty string indicates the beginning of the day. the date string format is more complex than is easily specified ented here but is fully described in the info documentation. environment tz Specifies the timezone, unless overridden by command line param-eters. if neither is specified, the setting from/etc/localtime is used. AUTHOR Written by David macenzie. reporting bugs Report date bugs to bug-coreutils@gnu.org GNU coreutils home page:
In this way, we can immediately know the specific usage of the date command, and also know the parameters that can be added by the date command, as well as the information about these parameters. For this interface, we call it man page ). We can see that "date (1)" is displayed in the first line after the man DATE command is input. The DATE here is the name of the command, (1) this indicates "commands that can be used by general users ". This number is very helpful in some cases. The common Linux numbers are as follows:
Meanings of common numbers
Code: Content 1 commands that can be operated by the user in the shell environment or tools that can run file 2 system core callable functions and tools 3 common functions) description of the device files in the library (libc) 4 of C, usually File 5 configuration files under/dev or the format of some files 6 games 7 Conventions and Protocols, etc, for example, Linux file system, network protocol, ASCII code, and so on 8 management commands available by the system administrator 9 files related to the kernelAfter entering the man date command, we found that there are many fields in the output information. What does the meaning of the fields that constitute man page mean?
Man page Components
DESCRIPTION of code content DESCRIPTION Brief commands and data names DESCRIPTION of SYNOPSIS short command release syntax (syntax) DESCRIPTION is a complete DESCRIPTION, this part is better to take a closer look! All the available OPTIONS listed in the OPTIONS section of SYNOPSIS indicate that COMMANDS can use this program (software) when it is running) the file command issued by the program or data is used or referenced or linked to some FILES can be referred to, see also, there are other instructions related to this command or data! For EXAMPLE, can you refer to the example bugs for related errors!We usually need to pay attention to the NAME and DESCRIPTION fields. NAME represents the NAME of the command, and DESCRIPTION is some common parameters of the command and their meanings. When we query commands on the man page, there are usually some commonly used buttons to help us:
Common man page buttons
Press the key to open a Page Down [Page Down] Flip a Page Down [Page Up] Flip a Page Up [Home] Go to the first Page [End] Go to the last Page/string 『Next "Search for the string. If you want to search for date, enter/date? String 『"Search for the string" n "and" N "to use // or? When searching strings, you can use n to continue the next search (whether/or ?) You can use N to perform reverse search. For example, if I use/date to search for the date string, I can use n to continue the query and use N to go up the query. To? To query the date string up by date, use n to continue the "up" query and use N to reverse query.Q
End man page
Note: These commonly used buttons can only be used on the man page.
Iii. shutdown command
In the previous article, we recorded that the Linux system's shutdown command can be shutdown-h now, And the restart command can be shutdown-r now or reboot, the command for shutdown and restart can only be executed by the root user. So what are the specific syntax rules for the shutdown command? What can be implemented by the shutdown command? No, let's ask man if we don't know.
[Root @ xiaoluo ~] # Man shutdownshutdown (8) // 8 indicates that the command is shutdown (8) NAME shutdown-bring the system downSYNOPSIS shutdown [OPTION]. TIME [MESSAGE] OPTIONS-r Requests that the system be rebooted after it has been brought down. -h Requests that the system be either halted or powered off after it has been brought down, with the choice as to which left up to the system. -H Requests that the system be halted after it has been brought down. -P Requests that the system be powered off after it has been brought down. -c Cancels a running shutdown. TIME is not specified with this option, the first argument is MESSAGE. -k Only sends out the warning messages and disable logins, do not actually bring the system down.
The syntax of the shutdown command is as follows:
[Root @ xiaoluo ~] # Shutdown [-t seconds] [-arkhncfF] time [Warning Information] Options and parameters:-t sec:-t followed by the number of seconds, that is to say, "Shut down in a few seconds" means-k: don't really shut down, just send a warning! -R: restart (commonly used) after the system service is stopped-h: Shut down the system service immediately after it is stopped. (Commonly used)-n: Shut down directly using the shutdown function without going through the init program.-f: After the system is shut down and started, force the disk check skipped by fsck-F: After the system is restarted, force fsck disk check-c: cancel the content of the shutdown command that is already in progress. Time: This is a required parameter! The system shutdown time! The time example is described below. Example: [root @ xiaoluo ~] # Shutdown-h 10' I will shutdown after 10 mins' # tell everyone that this machine will be shut down in ten minutes! It is displayed in front of the current login screen!
If we need to shut down, for example, set a certain time to shut down, we must add a time parameter, otherwise it will automatically jump to the level 1 running level (that is, single-user login ).
[Root @ xiaoluo ~] # Shutdown-h now // one of the most common commands for shutdown is to shut down immediately. now is equivalent to the status in which the time is 0 [root @ xiaoluo ~] # Shutdown-h the system shuts down at today. If this command is issued at, shutdown the system every other day [root @ xiaoluo ~] # Shutdown-h + 10 the system will automatically shut down in 10 minutes [root @ xiaoluo ~] # Shutdown-r now system restarts immediately [root @ xiaoluo ~] # Shutdown-r + 30 'the system will reboot' The system will restart in 30 minutes, and The following information will be displayed to all online users [root @ xiaoluo ~] # Shutdown-k now 'this system will reboot' only sends parameters for the warning letter! The system will not shut down! However, a warning message is displayed!
What is the use of the shutdown command? Or what can the shutdown command do?
- You can select the shutdown mode as needed: either to shut down, restart, or enter the single-user operation mode;
- You can configure the shutdown time: You can configure the current shutdown immediately, or you can configure a specific time to shut down.
- You can customize the shutdown information: before shutdown, you can send the information you configured to the online user.
- You can only send a warning message: Sometimes you may want to perform some tests, instead of disturbing other users, or tell users to pay attention for a period of time! In this case, you can use shutdown to scare users, but it is not really about shutdown!
- You can choose whether to use fsck to check the file system.
If you need to restart the instance, use the reboot command or shutdown-r now.
Iv. sync command
Although this command is simple, you still have to record it. The sync command synchronizes data to the disk.
In Linux, to speed up Data Reading, some data in the loaded memory will not be written back to the hard disk by default, but will be cached in the memory first, as a result, if a piece of data is repeatedly rewritten by you, it can be read directly from the memory because it has not been written to the hard disk. The speed must be quite fast!
However, this also causes some trouble, that is, in case your system is shut down abnormally due to some special circumstances (such as power outages or accidentally kicking power, because the data has not been written into the hard disk, wow! Therefore, the data upgrade is abnormal! What should we do? At this time, the sync command is required to write data! Enter sync directly under the text interface. data that has not been upgraded in the memory will be written to the hard disk! Therefore, this command is important before the system is shut down or restarted! It is best to run it several times more! The command is as follows:
[root@xiaoluo ~]# sync
For the sake of security, we recommend that you run the sync command several times to synchronize data in the memory to the hard disk before shutting down or restarting the system:
[root@xiaoluo ~]# sync[root@xiaoluo ~]# sync[root@xiaoluo ~]# sync[root@xiaoluo ~]# shutdown -h now