More excellent articles.

“Microservices are not all, just a subset of a specific domain”

Selection and process should be careful, otherwise it will be out of control.

Out of all the monitoring components, there’s always one for you

What are we Developing with Netty?

This is probably the most pertinent Redis specification

Portrait of a Programmer: A Decade of Ups and Downs

Most useful series:

The Most Common Set of “Vim” Techniques for Linux Production

The most Common set of “Sed” Techniques for Linux Production

The Most Common Set of “AWK” Tips for Linux Production


Linux has so many commands that it can be intimidating for beginners. The following is a list of commands that I have chosen to understand for those of you who are not familiar with Linux, combined with my daily work and in-house training at the company. Any of these commands can be used in depth, such as the difference between tail -f and tail -f. We don’t care, just use the most common examples. This article will not teach you the specific usage, that is to rob the man command of the rice bowl. This is just a guide. Keep it brief.

How to learn: Tap more and use conditioning to replace your brain memory — if you’re going to eat with it in the future or now. Among them, there are also some difficult to chew bones, we use sharp teeth together, to chew it up.

Check the status of the system

Directory operations

In my work, I often deal with directories and files. Linux provides commands to operate it, abstracted and abbreviated.

Basic operation

Perhaps these commands are used so often that it would be a sin to type more than one character. So they are short and can be counted by a scissorhand without Arabic numerals.



mkdir
cp
mv
rm

Example:

Create a directory and parent directories a,b,c,d
mkdir -p a/b/c/d

Copy folder A to/TMP
cp -rvf a/ /tmp/

Move file a to/TMP and rename it b
mv -vf a /tmp/b

Delete all files in TMP directory
rm -rvf /tmp/
Copy the code

roaming

Linux is dark on the command line, still facing life’s three questions: Who am I? Where I am? Where am I going?

The ls command displays all contents of the current directory. Ls-l can see more information and figure out who you are. Using the PWD command, you can view the directory where the current terminal resides. I’ll tell you where you are. CD If you go to the wrong place, the CD command can switch to the right directory. Find The find command filters a few criteria to find forgotten files.

Where to go may be the will of the master.

Text processing

This is a very, very plus skill. Once you get there, you can also save more time to study object orientation. Little Sister taste has exported the “most commonly used VIm, SED, AWK skills series”. The link is attached below. A common set of “VIM” Tips for Linux Production A common set of “Sed” Tips for Linux Production AWK Tips for Linux Production

Check the file

The cat command is the most commonly used. Note that if the file is too large, the output of cat command will be wildly printed on the terminal, which can be terminated by pressing CTRL + C several times.

Check the file size
du -h file

# View file contents
cat file
Copy the code

Less Since cat has this problem, for large files, we can open a file using less. Like vim, less can enter find mode after typing/and then press n(n) to look down (up). There are a lot of operations that are very similar to Vim, so you can look at them by analogy.

Most of you who do server-side development know this command. For example, look at the nginx scroll log.

tail -f access.log
Copy the code

The tail command can statically view the last n lines of a file, and the corresponding head command can statically view the last n lines of a file. But the head doesn’t have a rolling function, just like the tail is pointed outward, not backward.

tail -n100 access.log
head -n100 access.log
Copy the code

statistical

Sort and UNIq are often used in pairs. Sort can use -t to specify delimiters and -k to specify columns to sort.

The following command outputs the IP of the nginx log and the PV of each IP, the top 10 pv

# The 2019-06-26 T10:01:57 + 08:00 | nginx001. Server. Ops. Pro. Dc | 100.116.222.80 | 10.31.150.232:41021 | | | | 0.000 0.011 0.014 200 | 200 | 273 | | / visit | sign = 91 cd1988ce8b313b8a0454a4bbe930df | | - | - | HTTP POST | 112.4.238.213

awk -F"|" '{print $3}' access.log | sort | uniq -c | sort -nk1 -r | head -n10
Copy the code

other

Grep grep is used to filter content. The color parameter is displayed on supported terminals. The n parameter displays the number of lines for quick location. For example, view POST requests in nginx logs.

grep -rn --color POST access.log
Copy the code

It is recommended to use this parameter every time.

If I want to see the context before and after an exception, I can use the ABC parameter. They are abbreviations of several words and are often used. A after B before C count? N lines before and after the content would look like this:

grep -rn --color Exception -A10 -B2   error.log
Copy the code

diff

The diff command compares whether two files are different. Of course, this functionality is provided in all ides, and diff is just a crude compromise on the command line. By the way, diff and patch are still patched for some platforms. If you don’t use it, pass it.

The compression

Compression is generally enabled to reduce the size of the transferred files. Common compressed files in Linux include tar, bzip2, zip, and rar. 7z is rarely used.

.tar



.bz2



.gz



.zip



.rar

The most common is the.tar.gz file format. In fact, it is tar packaged and then compressed using gzip.

Creating a compressed file

tar cvfz  archive.tar.gz dir/
Copy the code

Unpack the

tar xvfz. archive.tar.gz
Copy the code

Go find out what the relationship is.

Daily operations

To turn on is to press the start button, but to turn off is not to press the start button. The shutdown command is used to shutdown users. . The passwd command can be used to change passwords, but this permission is still available.

mount


mount /dev/sdb1 /xiaodianying
Copy the code

Chown The chown command is used to change the owning user and owning group of a file. The chmod command is used to change the file access permission.

Both of these commands are related to the Linux file permission 777. Example:

# Destructive command
chmod 000 -R /

Change the user and group of directory a to XJJ
chown -R xjj:xjj a

# add execute permission to a. Sh file
chmod a+x a.sh
Copy the code

Assuming you are using centos, the package management tool is yum. If your system does not have the wget command, you can use the following command to install it.

yum install wget -y
Copy the code

Systemctl oF course, centos management background services also have some routines. The service command is. Mysql > restart mysql; The following one is recommended.

service mysql restart
systemctl restart  mysqld 
Copy the code

For normal processes, use the kill command for more detailed control. The kill command has many signals. If you’re using kill -9, you’ll want to know the difference between kill -15 and kill -3.

Su su is used to switch users. For example, if you are now root and want to do something as an XJJ user, you can su switch.

su xjj
su - xjj
Copy the code

– Can let you come clean and pure another account, no accidents, recommended.

System status overview

Log in to a Linux machine and some commands will help you find problems quickly. These commands cover memory, CPU, network, IO, disk, and so on. For more information, refer to the five-piece set. A little higher order. Linux “Cast Away” (1) Preparation for Linux “Cast Away” (2) CPU Linux “Cast Away” (3) memory Linux “CAST Away” (4) I/O Linux “Cast Away” (5) network

Uname The uname command outputs information about the current kernel, giving you an idea of what machine you are using.

uname -a
Copy the code

Ps The ps command displays the status of processes and threads. Some overlap with top, often used.

# Find the Java process
ps -ef|grep java
Copy the code

Top Indicates the system status. CPU Load Load and CPU usage. Use the process with the highest memory or CPU. The following command can view the thread status in a process.

top -H -p pid
Copy the code

Free Top also looks at memory, but it’s not friendly. Free is dedicated to looking at memory. Includes physical memory and virtual memory swap.

Df Using the df command, you can view the disk usage in the system and check whether the disk usage has reached the upper limit. The h argument can be displayed in a friendly way.

df -h
Copy the code

Ifconfig displays the IP address. The alternative is the IP addr command.

Ping You can use ping to check whether the network is normal. (Excluding sites that ban ping)

Netstat Although the ss command can replace netstat, netstat is still more widely used in practice. For example, view all current TCP connections.

netstat -ant
Copy the code

This command is very useful in finding out what port is used locally.

Work commonly used

There are also some commands that are often used at work, and they come up very frequently, and they are familiar faces.

Export Many students who have installed JDK can not find Java command, export can help you to do it. The export command is used to set some environment variables. The env command shows all environment variables in the current system. For example, the following Settings are JDK.

export PATH=$PATH:/home/xjj/jdk/bin
Copy the code

Sometimes, you want to know the exact path of the command being executed. Using whereis, I’m assuming you have multiple versions of the JDK installed.

Crontab is the job tool native to Linux. It’s not distributed. If you’re not in operations, don’t use it. For example, remind yourself to go to the bathroom every 10 minutes.

*/10 * * * * /home/xjj/wc10min
Copy the code

Date The date command displays the current system time. You can specify the output format using the -s parameter. But setting the time involves setting the hardware, so there is another command called hwclock.

Xargs Xargs reads the input source and processes it line by line. This command is very useful. For example, delete all the class files in the directory.

find . | grep .class$ | xargs rm -rvf

Copy all RMVB files to the directory
ls *.rmvb | xargs -n1 -i cp {} /mount/xiaodianying
Copy the code

network

Linux is a multi-job network operating system, so there are many, many network commands. In my work, I deal with them most often.

SSH, I don’t want to talk about SSH. You’ll want to know what an SSH tunnel is. If you want detailed output, add -v.

SCP SCP is used for file transfer. It can also be used to transfer directories. There are also more advanced SFTP commands.

SCP a.tuxt 192.168.0.12:/ TMP/a.tuxt SCP -r a_dir 192.168.0.12:/ TMP /Copy the code

Wget If you want to install the JDK on the server, don’t download it locally and then use SCP to upload it to the server (sometimes you have to). The wget command allows you to download files directly from the command line and supports breakpoint continuation.

wget -c http://oracle.fuck/jdk2019.bin
Copy the code

Mysql is widely used and not everyone has access to Navicat. You need to understand the mysql connection and basic operations to be able to handle exceptions.

Mysql -u root -p -h 192.168.1.2Copy the code

End

Don’t feel complicated, the command is limited, but the passion is infinite; Will not be proud, a VIM is enough to toss for a lifetime. The shortcut is to summarize, in-depth only exploration. White horse through the gap, will eventually flow, easy. Things get old, things get old. Only time, will not live up to.