Linux Common commands for viewing logs
1. Common commands for viewing logs
tail:
-n Is the line number displayed ; amount to nl command ; Examples are as follows :
tail -100f test.log Real time monitoring 100 Line log
tail -n 10 test.log Query log tail last 10 Log of lines ; tail -n +10 test.log query 10 All logs after line ; head:
Follow tail It's the opposite ,tail How many lines of log after reading ; Examples are as follows : head -n 10 test.log Query header in log file 10 Line log ; head -n -10
test.log Query log file except last 10 All other logs of the line ; cat: tac It's in reverse order , yes cat Reverse writing of words ; Examples are as follows : cat -n test.log
|grep "debug" Query keyword log
*
Application scenario 1 : View by line number — Filter out logs near keywords

1)cat -n test.log |grep “debug” Get the line number of the Key log

2)cat -n test.log |tail -n +92|head -n 20 Select the middle line of the keyword . And then look at this keyword before 10 Line and after 10 Log of lines :
tail -n +92 Represents a query 92 Log after line head -n 20 In the previous query results 20 Records
*
Application scenario 2 : Query logs by date

sed -n ‘/2014-12-17 16:17:20/,/2014-12-17 16:17:36/p’ test.log

Special instructions : The two dates above must be printed from the log , Otherwise, it is invalid ;
before grep '2014-12-17 16:17:20' test.log To determine whether the point of time
4. Application scenario 3 : The log has a lot of content , Printing on the screen is not convenient to view
(1) use more and less command , as : cat -n test.log |grep "debug" |more This will print in pages , Turn the page by clicking the space bar
(2) use >xxx.txt Save it to a file , We can pull down the file analysis as :cat -n test.log |grep "debug" >debug.txt
<> <> log file

day Records writing Case study bright
/var/log/message Information and error log after system startup , yes Red Hat Linux One of the most commonly used logs in
/var/log/secure Security related log information
/var/log/maillog Message related log information
/var/log/cron Log information related to scheduled tasks
/var/log/spooler And UUCP and news Device related log information
/var/log/boot.log Log messages related to the start and stop of the daemons
<> <> system

Command description
uname -a View kernel / operating system /CPU information
cat /etc/issue Login information display data
cat /etc/redhat-release View operating system version
cat /proc/cpuinfo see CPU information
hostname View computer name
lspci -tv List all PCI equipment
lsusb -tv List all USB equipment
lsmod List loaded kernel modules
env View environment variables
<> <> resources

Command description
free -m View memory usage and swap usage
df -h Check the usage of each partition
du -sh < Directory name > View the size of the specified directory
grep MemTotal /proc/meminfo View total memory
grep MemFree /proc/meminfo View the amount of free memory
uptime View system runtime , Number of users , load
cat /proc/loadavg View system load
<> <> Disks and partitions

Command description
mountcolumn -t # View attached partition status
fdisk -l # View all partitions  
swapon -s # View all swap partitions  
hdparm -i /dev/hda # View disk parameters ( Only for IDE equipment ) 
dmesggrep IDE # View on startup IDE Equipment testing status
<> <> network

Command description
ifconfig View the properties of all network interfaces
iptables -L View firewall settings
route -n View routing table
netstat -lntp View all listening ports
netstat -antp View all established connections
netstat -s View network statistics
<> <> process :

Command description
ps -ef View all processes
top Real time display of process status ( Another article has a detailed introduction )
<> <> user :

Command description
w view active user
id < user name > View specified user information
last View user login log
cut -d: -f1 /etc/passwd View all users of the system
cut -d: -f1 /etc/group View all groups in the system
crontab -l View the current user's scheduled tasks
<> <> service :

Command description
# chkconfig –list List all system services
`# chkconfig –listgrep on`
<> <> program :

Command description
# rpm -qa View all installed packages

Technology