Commonly used in the work of Linux commands

Foreword

Only the head can become strong.

Text has been included to my GitHub repository, welcome Star: github.com/ZhongFuChen...

Prior he wrote, " in the company doing the project in the school and their own do what's the difference? "Do not know if you do not have the impression, which refers to the job may take on a Linux server, view some of the information (in particular, check the log to find Bug).

I had Linux courses in college, also done during the Linux-related notes:

However, completion of the school, did not ye practice hand (or too dishes), go to the company can be said to forget all the light. This article is mainly to review previous notes, and record it in the work of some of the more commonly used commands.

  • I'm sure this is my current dimensions to consider, and I work long relatively short, so there may be a lot of command ignored, please add in the comments area

How so rubbish I TM

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
  • (Obviously not enough)

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

1GB size of daily log output

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.logThis 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 13888888888

Such a practice, you can be service.logall contained 13888888888records to search out, speed is really fast search of.

Retrieve logs

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 catcommand followed by a -nparameter just fine. So the command is: cat -n service.log | grep 13888888888, as shown we can be found in the corresponding line number

Check the number of rows

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.txtThe 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

Check the number of rows

References:

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 grepto filter out processes you want to check, for example:ps -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

View details of a port

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:

At last

I work for a relatively short length of time, so there may be a lot of command ignored, please add the more commonly used commands in the comments area. If you follow some commands more important, I would like to share ha ~

Willing output of dry cargo of Java technology public number: Java3y . A public number more than 200 original articles technical articles, massive video resources, beautiful mind map, attention can get!

Forwarded to the circle of friends is the biggest support for me!

I think the article is well written, points praise !

Guess you like

Origin juejin.im/post/5d3857eaf265da1bd04f2437