There are several commands for Linux to view logs: Tail, Cat, TAC, head, Echo
A. View Log mode
command format: tail[necessary parameters [select parameters] [file]
This is one of my most common ways to view
1.tail
-F Loop Read
-Q does not display processing information
-V display detailed processing information
-c< number > displayed bytes-n< number of
rows > number of rows-
Q,--quiet,--silent Never outputs the first-s of the filename
,--sleep-interval=s and-F, which means that the
tail- n test.log is dormant at each recurring interval Log the last 10 lines of the tail of the query log;
Tail -N +10 test.log queries all logs after 10 rows;
Tail -fn test.log Loop Real-time view of the last 1000 lines (most commonly used)
//typically with grep, for example: TAIL-FN 1000 Test.log | grep ' Keywords '
if the amount of data in a single query is too large, you can flip the page to view,
for example: Tail-n 4700 aa.log |more-1000 can display multiple screens (CTRL + F or the SPACEBAR can be shortcut keys)
2.head
Head-n test.log //query log files in the first 10 lines of log;
Head-n -10 test.log //query log file except for all other logs of the last 10 lines;
Head other parameters are similar to the tail
3.cat
Cat is displayed continuously on the screen from the first line to the last line
Show entire file at once: $ cat filename
creates a file from the keyboard: $ cat > FileName
merge several files into one file: $cat file1 file2 > File//Can only create new files and cannot edit the There are files.
Appends the contents of one log file to another: $cat-n textfile1 > Textfile2
note:> means that creating,>> is append. Don't get mixed up.
Cat other parameters are similar to tail
4.tac
The TAC is displayed on the screen from the last line to the first line.
5.sed
This command can look for a specific section of a log file, or it can be queried based on a range of times
By line number
sed-n ' 5,10p ' filename//So you can view only the 5th line to the 10th line of the file.
//According to the time period
sed-n '/2014-12-17 16:17:20/,/2014-12-17 16:17:36/p ' test.log
6.less
Less
the log.log shift + G command to the end of the file and then enter. Plus the keywords you want to search for, for example. Switch between 1213 shift+n keywords
two. Other commands to be applied
History//All history
History | grep XXX //History records containing certain instructions history | more//
paging View records
HISTORY-C//Clear All history
!! Repeat the previous command
query after the record is checked:!323
Linux log file description
/var/log/message information and error logs after system startup is one of the most common logs in red Hat Linux
/var/log/secure Security-related log information
/var/log/maillog Mail-related log information
/var/log/cron log information related to timed tasks
/var/log/spooler log information related to UUCP and news devices
The/var/log/boot.log daemon starts and stops related log messages
/var/log/wtmp This log file to permanently record each user's logon, logoff, and system startup, downtime events