Used to work in Linux commands

I. View Log

Online there is a problem, check the log to board machine line is very common in the operation. The first time I boarded the online machine check log, I also remember the following few commands (we assume now called the log file service.log):

  • cat service.log

  • tail -f service.log

  • vim serivice.log

Now log daily output of about the size of 1GB:

If the file is small, then a simple catcommand can still cope with, but if you directly catopen a 1GB log file command to ensure that you get stuck ( ctrl + cexit catcommand takes a long time to be cata command to stop).

  • I usually just use catwhat to see this small text file is

Likewise, if the file is small, simple vimcommand to open a file is manageable, but if you use vimthe command to open a 1GB or even larger files, and can obviously feel the slow and Caton.

I usually like to use vimto find the corresponding record, I generally operations:

  • vim service

  • Press Gjump to the end of the file

  • Press ? + keyword search corresponding record

  • Press nup inquiries, press Ninquiries down

tail -f service.log This command is used to view the traffic if I generally come in (or when debugging log can be seen directly, then quickly ctrl +cturn off)

Face relatively large log files, with which we have to grepplay, and such as we now know a phone number can not receive SMS verification code, you want to look at the phone number of the log is kind of how. So we can do this:

  • cat service.log | grep error

Such a practice, will be able to service.logall records containing the error to search out, speed is really fast search of.

 

Now that we have been able to search based on keywords corresponding to the record, and then I want to see the log context of that record [so that you know about the status of the implementation of this data]

First of all, we need to identify the row number of the corresponding record in the cat command followed by a  parameter just fine. So the command is: , as shown we can be found in the corresponding line number -ncat -n service.log | grep error

Now the number of lines is 29506, we generally just look at the first 10 rows and 10 rows back 29506 of almost know where the problem, so we can do this:

  • sed -n "29496,29516p" service.log: Start retrieving the line from 29496 to 29516 end of line

  • cat -n service.log | tail -n +29496 | head -n 20: From 29496 start retrieving the line, to push forward 20

If the keyword is not accurate (too much of the logging output), we can use the morecommand to browse or output to a file and then analysis:

  • cat service.log | grep 13 |more : The result of the inquiry referred to more output

  • cat service.log | grep 13 > /home/sanwai/aa.txt  The result of the query is written /home/sanwai/aa.txton the file

Sometimes, we want to count how many rows this log output, we can use this command:

  • cat service.log | wc -l

 

References:

  • https://www.cnblogs.com/xiashan17/p/7059978.html

Second, the investigation process and port

The investigation process has two commands:

  • ps -ef

  • ps aux

These two commands are listed all the processes, or through our pipeline and  to filter out processes you want to check, for example: |grepps -ef |grep java

The check out process Why? Know the process ID, we can put him to kill.

  • kill -9 processId: Kill a process

Check the port is also a very common operation, common commands: netstat -lntup:

l:listening   n:num   t:tcp  u:udp  p:display PID/Program name for sockets

查看当前所有tcp/udp端口的信息

View a port details:lsof -i:4000

Third, view the status of the system

3.1 TOP real-time view of the status process

TOP command to check the status of the process, which has a load average may not be so easy to understand, explain the following:

load average: within a specific time interval run queue (running on the CPU or waiting for how many processes running) the average number of processes .

load average has three values, representing: 1 minute, 5 minutes, 15 minutes The average number of processes running within the process queue.

  • The average number of processes running processes + ready and waiting for the process to run at a specific time (1 minute, 5 minutes, 10 minutes) of

Linux process can be divided into three states:

  • Blocking process

  • The process can be run

  • Running processes

For example, the system now has two running processes, three processes can run, then the system load is 5, load average is the number of load within a certain time mean .

3.2free view memory usage

thinking of linux memory management mechanisms include (can not say that) memory utilization is maximized , the kernel will the remaining memory application is cached , and the cached does not belong to free category.

If not enough free memory, the kernel will partially cached in memory recovery , recovered memory reallocation to the application. So for linux system, memory available for allocation is not only free memory, further comprising a cached memory (in fact, further comprising buffers).

  • Available memory = free memory + buffers + cached memory

Buffer Cache and Page Cache. The former disk blocks for reading and writing, which read and write file for the inode. These Cache effectively shortening the time I / O system calls (such as read, write, getdents) of. Operation of the disk has a logic level (file system) and a physical level (disk block)

References:

  • https://blog.csdn.net/zhangchenglikecc/article/details/52103737

  • https://www.cnblogs.com/peida/archive/2012/12/24/2831353.html

Guess you like

Origin www.cnblogs.com/gaomanito/p/11585715.html