Hello everyone, I’m Xindoo, today I’d like to share my next opinion — programmers should learn some Linux commands! This has been my personal experience in back-end development for the past two years. Those who know me probably know that my career is quite “special”. After graduation, I first worked in operation and maintenance, and then switched to Java development. The o&M experience was pretty tough, but one of the things I learned was that I was familiar with most of the common Linux commands. I’ve lost count of the number of times I’ve used just a few lines of command to do something that nobody else has done for a long time, and then just left, hiding my reputation…

What’s the use of learning Linux commands?

There are countless examples of everyday improvements using Linux commands, but I’ll mention some that have worked for me.

Quickly troubleshoot and locate problems

Take a very simple scenario, go to work in the morning, just sit down and suddenly receive a server alarm, CPU utilization is 98%! You can run the top command on the server to quickly locate the process or thread. You can run the SAR command to locate the time when the fault occurs. You can run the cat and grep commands to quickly locate the logs when the fault occurs. To solve the problem in minutes. While the master makes a cup of tea to solve the problem, the novice is still at a loss.

About the command to locate the performance problem, I translated the article before 10 lines command 60 seconds fast locate the performance bottleneck, you can learn about it.

Data cleaning and statistics

There are many methods for data cleaning and statistics. For example, Excel can be used to complete many types of statistical work, but for some simple statistics, I can write a shell script and do it in minutes, especially when the data to be counted is directly on the server. For example, how many times did the service staff report error on this machine today? And the average, maximum, minimum time taken to resolve all requests for an interface from the log today… Such simple data cleaning and statistics, I use grep, AWk can also be completed in minutes.

I have a deep impression on my experience. Once when we were investigating a certain problem, we exported two copies of user data from two systems to compare the data difference of each user in the two systems. At that time, the amount of data was quite large. What would you do with a problem like that? Pull from the server to the local, and then use Excel vlookup seems to work. What if the server doesn’t allow data to be downloaded?

If these two pieces of data are two tables in the database, it is obvious that the two tables are directly joined together (some colleagues also proposed to enter the data into the database first at that time). But it’s easy to do this on Linux with awk, and I wrote a blog post about how AWK implements SQL like join operations.

Secondary development

For example, I use wget command to download files, use curl command to debug interface, use DIG, ping, NC test network, use WRK pressure test interface……

With X

This will not say more, in the console various types of knocking, very geek.

How to learn Linux commands

There are so many advantages to learning Linux commands that I’m sure you can’t wait to learn. Here are some of my tips.

Practice, but don’t try too hard

This is a cliche, but it takes a lot of deliberate practice to become proficient, and learning Linux commands is no exception. A word of caution, though, is that it’s not necessary to spend too much time mastering a Linux command at once, especially if it’s a relatively obscure one. If you don’t use them for a long time, you will forget them and have to learn them again. The input/output ratio is too low.

For example, I learned how to use tcpdump before, and most of the parameters were used. However, TCPdump was rarely used in daily work and involved a lot of network knowledge. I had not used it for a long time and had forgotten how to use it. For commands that are not often involved in the job, it is enough to know what it can do, and then to learn when there is a real need.

Know what the command is, and then how to use it

Linux commands and their parameters can not be described in a zillion words, but it is also numerous, most of the commands and parameters will not be used, but it is recommended that you note a little. For example, when I was OOM OOM this morning, I wanted to trace the load of the machine during that period of time. The simplest way is to use SAR command, which is convenient and quick. Although I have forgotten the specific parameters, MAN or search will know immediately.

So my advice is to know what the commands are, and then learn how to use them as required. Beginners should start with the simplest and most commonly used commands, such as the commands shown in the figure below.

There are plenty of reference guides for common commands online, and I’ve written a blog post about them beforeMy usual Linux command

Use MAN and search engines

In Linux, the use of all commands can be through the man command to query, including detailed schematic, have the effect of various parameters, provides are ordered the developer must guarantee the accuracy, but the disadvantage is that is in English, and some length is longer, to the English not very good people like me is not very friendly.

Search engines are also a great way to learn how to use Linux. There are various blogs on the web, and some portals (such as Beginner tutorials) have more systematic teaching content, and sometimes even find solutions to your problems. This way is more friendly to novices, but the disadvantage of this way is that the quality of the content is uneven, they have to do a good job of information discrimination and screening.

For Linux commands that I am not familiar with, I use both methods on a daily basis and prefer the second one. However, when the second one fails to solve my problems, I will go to man collection to find more professional information.

Favorites code snippets

I may be a bit pragmatic. Most of the time, I learn Linux commands to solve specific problems, and the problems I encounter are varied and the methods I use are different, which may be repeated after a long time, and by the time they occur, the solutions I used have long forgotten. To avoid this problem, I started using snippetsLab to record frequently used snippets, storing my slightly more complex and less frequently used snippets with descriptions and tags for easy retrieval and quick retrieval if needed later.

For example, the function of AWK to implement JOIN in the above article is slightly complicated. It is not impossible for me to write it again every time, but it still needs some time to debug. Instead of adjusting it every time, record it next time and use it directly. I’ve logged hundreds of snippets in snippetsLab over the last two years.

conclusion

To be honest, while I don’t recommend operations, especially in China, I do recommend that you learn about operations, especially the various common Linux commands, whether you are front-end or back-end, just Java or GO.