Hello everyone, I am xindoo, today I will share with you my next point of view-programmers should learn some Linux commands! This is also my personal experience of doing back-end development in the past two years. Anyone who knows me may know that my career is "special". After graduation, I first did operation and maintenance, and then switched to Java development. The experience of operation and maintenance is miserable, but the accumulated experience in operation and maintenance has benefited me a lot after switching to development. One of them is to be familiar with most of the commonly used Linux commands. I can’t remember how many times I used only a few lines of commands to get things done that others didn’t get done for a long time.
What is the use of learning linux commands?
There are countless examples of using linux commands to improve efficiency on a daily basis. I will talk about some obvious effects on me.
Quickly troubleshoot and locate problems
For a very simple scenario, I went to work in the morning, and I just sat down and suddenly received an alarm from the server. The CPU usage rate was 98%! The top command of the login server can quickly locate which process or thread. The sar command locates the time point of the problem. Use cat, grep and other commands to quickly find the log when the problem occurred... and solve the problem in minutes. When the master's skill in making a cup of tea solves the problem, the novice is still at a loss.
Regarding the commands for locating performance problems, I have previously translated an article 10 lines of commands in 60 seconds to quickly locate the performance bottleneck are interested, you can learn about it.
Data cleaning and statistics
There are many methods for data cleaning and statistics. For example, you can use excel to complete many types of statistics. But for some simple statistics, I can write a shell script to do it in minutes, especially when the data that needs to be counted is straightforward. When on the server. For example, how many errors have been reported by employees on this machine today? In addition, the average, maximum, and minimum time consumption of all requests for a certain interface today can be parsed from the log... Such simple data cleaning and statistics can be completed in minutes with grep and awk.
An impressive experience. Once when we were troubleshooting a problem, we exported two user data from two systems. I wanted to compare the data differences between each user in the two systems. At that time, the amount of data was still quite large. of. What would you do with this kind of problem? Pull from the server to the local, and then use excel's vlookup seems to work. When the data on the server is not allowed to download?
If the 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 store the data in the database first). But using awk command on Linux can easily achieve this function. Later, I also wrote a blog the specific method 161b0ac621253c awk implements sql-like join operation .
Assisted development
There are countless things to assist in development. For example, I use wget command to download files, curl command to debug the interface, use dig, ping, nc to test the network, and use wrk to pressure test the interface...
Install X
I won't say much about this, all kinds of knocks in the console, very geek.
How to learn Linux commands
The above mentioned a lot of the advantages of learning Linux commands, I believe you definitely can't help but want to learn, here I share some of my learning methods.
Practice more, but there is no need to practice too deliberately
This can be regarded as a cliché. It takes a lot of deliberate practice to learn how to be proficient, and learning Linux commands is no exception. But here is a piece of advice, that is, there is no need to spend too much time to master a certain linux command, especially some relatively unpopular commands. Many commands are really not commonly used. If you are obsessed with mastering all its parameters at once, but you will definitely forget it if you don't use it for a long time, you still have to learn it again when the input-output ratio is too low.
For example, I have learned the use of tcpdump before. At that time, most of the parameters were basically used, but tcpdump was used too little in daily work, and it also involved a lot of network knowledge. I have not used it for a long time. I have forgotten how to use it. Commands that are not involved in this kind of work and are not commonly used. Just understand them, know what it can do, and learn them when there is a real need.
First know what kind of commands are available, and then consider how to use them
Linux commands and their parameters cannot be described in a vast array of smoke, but they are countless. Most of the commands and parameters will not be used at all, but it is recommended that you record them a little. For example, I encountered an early morning OOM problem this morning. I want to trace the load situation of the machine during that period. The easiest way is to use the sar command, which is convenient and fast. Although I have forgotten the specific parameters, man or search Know it right away.
So my suggestion is to first know what kind of commands are available, and then learn how to use specific commands according to your needs. Beginners should start with the simplest and most commonly used commands, such as the commands in the figure below.
There are many reference guides for commonly used commands on the Internet. I also wrote a blog before My commonly used Linux commands
Make good use of man and search engines
In Linux, the usage of all commands can be queried through the man command, including detailed instructions. Various parameters have functions. They are provided by the developer of the command. They are sure to be accurate, but the disadvantage is that they are all in English. Yes, and some of them are longer, and they are not very friendly to people like me who are not good at English.
In addition, search engines are also a good tool for understanding how to use Linux. There are various related blogs on the Internet, and some introductory websites (such as the rookie tutorial) also have more systematic teaching content, and sometimes they can even find solutions to your problems. This method is more friendly to novices, but the disadvantage of this method is that the quality of the content is uneven. You have to distinguish and filter the information yourself.
For linux commands that I am not familiar with, I use both methods daily, and prefer the second method, but when the second method cannot solve my problem, I will look at the man collection to find more professional information.
Favorite code snippets
I may be more pragmatic. In most cases, I learn linux commands to solve specific problems. The problems I have encountered are various and the methods used are different. It may appear repeatedly after a long time. The solution used before the time has long been forgotten. To avoid this kind of problem, I started to record some commonly used code snippets with snippetsLab, save the slightly more complicated and not very commonly used code snippets that I wrote, add descriptions and tags for easy retrieval, and later, if you use them again, you can quickly find them. Back.
For example, the join function implemented by awk in the above is a bit complicated, and it is not impossible to write it every time I rewrite it, but it still takes some time to debug. Rather than adjusting this every time, it is better to record it and post it next time and use it directly. I have recorded hundreds of code snippets in snippetsLab in the past two years.
Concluding remarks
To be honest, although I do not recommend doing operation and maintenance work, especially in China, I highly recommend that you understand the skills related to operation and maintenance, especially various commonly used Linux commands, whether you are front-end or back-end, but If you are a java or go programmer, you should understand the commonly used linux commands.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。