Organize common commands for viewing system logs in Linux
Organize common commands for viewing system logs in Linux
Last
-A displays the host name or IP address from which to log on to the system in the last line.
-D specifies the record file. Specifies the record file. Converts an IP address to a host name.
-F <Record File> specifies the record file.
-N <display columns> or-<display columns> sets the number of columns displayed in the list.
-R does not display the host name or IP address used to log on to the system.
-X: displays information such as system shutdown, reboot, and change of execution level.
The following describes all restart and shutdown records.
last | grep rebootlast | grep shutdown
History
List all history records:
[zzs@Linux] # history
Only the last 10 records are listed:
[Zzs @ linux] # history 10 (Note: there are spaces between history and 10)
Use the Command record number to execute the command and execute the 99th commands in the History List
[Zzs @ linux] #! 99 (! There is no space in the middle of "and" 99)
Repeat the previous command
[zzs@linux] #!!
Run the last command starting with rpm (!? ? It indicates a String, which can be input at will. Shell searches forward from the last historical command, and the first matched command will be executed .)
[zzs@linux] #!rpm
List all history records on a screen:
[zzs@linux]# history | more
Clear all history commands of history now
[zzs@linux] #history -c
Cat, tail, and watch
All the system logs are read by yourself under/var/log (you can check the specific usage, and the appendix lists some common logs)
Cat/var/log/syslog and other cat/var/log/*. log
Tail-f
If the log is being updated, how can I view tail-f/var/log/messages in real time?
You can also use watch-d-n 1 cat/var/log/messages
-D indicates the highlight of different places, and-n indicates the number of seconds to refresh.
This command does not directly return the command line, but prints newly added content in the log file in real time,
This feature is very effective for viewing logs. To terminate the output, press Ctrl + C.
In addition, there are more, less, dmesg | more, which will not be listed here. Because there are too many commands, the key is personal preferences and business needs.
Linux Log File description
/Var/log/message information and error logs after the system is started. It is one of the most common logs in Red Hat Linux.
/Var/log/secure security-related log information
/Var/log/maillog and mail-related log information
/Var/log/cron log information related to scheduled tasks
/Var/log/spooler logs related to UCP and news Devices
/Var/log/boot. log daemon starts and stops related log messages
/Var/log/wtmp this log file permanently records the logon, logout, and system startup and shutdown events of each user.