On Linux, the most commonly used batch of command parsing (selected in 10 years)

Source: taste of little sister

ID:xjjdog

Author: Miss’s dog

Linux has so many commands that beginners are often intimidated. The following is a collection of commands that I have to understand in combination with my daily work and internal training of the company for students who are not familiar with Linux. Any command 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 job of man command. It’s just a guide, trying to be concise.

Learning style: knock more, hit more, and use conditioned reflex instead of brain memory – if you want to eat with it in the future or now. Among them, there are also some hard to swallow bones, concerned about the little sister flavor WeChat public number, we use sharp teeth to chew it up.

Content: ✔ directory operation ✔ text processing ✔ compression ✔ daily operation and maintenance ✔ system status overview ✔ common work

Directory operation

In the work, the most common thing to deal with is the operation of directories and files. Linux provides corresponding commands to operate it, and abstracts and abbreviations these commands.

basic operation

Maybe these commands are too common. It’s a sin to type one more character. So they are all very short. Without Arabic numbers, you can count them with a pair of scissors.

A660202 see the order MKDIR create directory & nbsp; make dir CP copy file & nbsp; copy MV move file & nbsp; move RM & nbsp; remove file

Example:

#Create directory and parent directory a, B, C, D MKDIR - P A / B / C / D ා copy folder a to / tmp directory CP - RVF A / / TMP / ා move file a to / tmp directory, and rename to B MV - VF A / TMP / b ා delete all files RM - RVF on the machine/

Roam

Linux is the black command line, still have to face life three questions: who am I? Where am i? Where am I going?

The LS & nbsp; command can see all the contents of the current directory. LS – l can see more information and judge who you are. The PWD & nbsp; command can see the directory where the current terminal is located. Tell you where you are. CD & nbsp; if you go to the wrong place, the CD command can switch to the right directory. The find & nbsp; find command can find forgotten files by filtering some conditions.

As for where to go, it may be the will of the master.

text processing

It’s a very, very good skill. After get, it can also save more time to study object-oriented. The taste of little sister has output “the most commonly used VIM, SED, awk skill series”. A link is attached below. In Linux production environment, the most commonly used set of “VIM” skills, in Linux production environment, the most commonly used set of “sed” skills, in Linux production environment, the most commonly used set of “awk” skills

see file

Cat command is the most commonly used command in cat. Note that if the file is large, the output result of cat command will be output crazily on the terminal. You can press Ctrl + C multiple times to terminate.

#View file size Du - H file view file content cat file

Since the cat of less has this problem, we can use the less command to open a file for a larger file. Similar to VIM, less can enter search mode after entering / and press n (n) to search down (up). There are many operations that are similar to vim. You can compare them.

Most of the students who are doing server development in tail know this command. For example, check the scrolling log of nginx.

tail -f access.log

The tail command can view the last n lines of a file statically. The head command can view the first n lines of a file. But the head has no rolling function, just like the tail goes to the foreign minister, not to the inside.

tail -n100 access.loghead -n100 access.log

Statistics

Sort and uniq are often paired. Sort can use – t to specify the separator and – K to specify the columns to sort.

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

#2019-06-26T10:01:57+08:00|nginx001.server.ops.pro.dc|100.116.222.80|10.31.150.232:41021|0.014|0.011|0.000|200|200|273|-|/visit|sign=91CD1988CE8B313B8A0454A4BBE930DF|-|-|http|POST|112.4.238.213awk -F"|" '{print $3}' access.log | sort | uniq -c | sort -nk1 -r | head -n10

Other

Grepgrep is used to filter the content. With the — color parameter, you can print the color on the supported terminals. With the parameter n, you can output the specific number of lines for quick positioning. For example: check the post request in the nginx log.

grep -rn --color POST access.log

It is recommended to use this parameter every time.

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

grep -rn --color Exception -A10 -B2   error.log

Diff

The diff command is used to compare the differences between two files. Of course, this function is provided in the IDE, and diff is just the original compromise under the command line. By the way, diff and patch are still some ways to patch the platform source code. If you don’t use them, pass them.

compress

In order to reduce the size of the transfer file, compression is generally turned on. The common compressed files under Linux are tar, bzip2, zip, rar, etc., and 7z is relatively less used . Tar & nbsp; use tar command to compress or decompress. Bz2 use bzip2 command to operate. GZ use gzip command to operate. Zip use unzip command to decompress. Rar use Unrar command to decompress

The most commonly used is the. Tar. GZ file format. In fact, after tar packing, gzip compression is used.

Create a compressed file

tar cvfz  archive.tar.gz dir/

decompression

tar xvfz. archive.tar.gz

Let’s find out the relationship between them.

Daily Operation

Power on is to press the start button, and power off is not to press the start button for a long time. By the way, it’s the shutdown command, but generally it doesn’t have permission -. -!. The passwd command can be used to change the password. This permission is still available A660205 the mountmount command can be attached to some external devices, such as U disk, such as ISO, such as the newly applied SSD. You can watch a small movie at ease.

mount /dev/sdb1 /xiaodianying

Chownchown is used to change the users and groups to which a file belongs. Chmod is used to change the access rights of files.

These two commands are related to the file permission 777 of Linux. Example:

#The destructive command Chmod 000 - R / ා modify the users and groups of a directory to xjjcown - R xjj: xjj a ා add execution permission to a.sh file (this is too common) Chmod a + X a.sh

If you use 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

System CTL, of course, there are some ways for CentOS to manage background services. The service command is. Systemctl is compatible with the service command. Let’s see how to restart MySQL service. &Nbsp; the following is recommended.

service mysql restartsystemctl restart  mysqld

For ordinary processes, you need to use the kill command for more detailed control. The Kill Command has a lot of signals. If you are using kill-9, you must want to know the difference and use of kill-15 and kill-3.

Susu is used to switch users. For example, you are root now. If you want to do something with xjj users, you can use Su switch.

su xjjsu - xjj

-Can let you come to another account clean and pure, no accident, recommended.

System status overview

Log in to a Linux machine. Some commands can 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. Higher order. The command a660206 unameaname in Linux can output the current kernel information and let you know what machine you are using.

Uname -a

The PSPS command can see the process / thread status. There are some overlaps with top, which are often used.

#Find the java process PS - ef| grep Java

Top system status list, mainly for viewing. CPU load, CPU utilization. Some processes that use the most memory or CPU. The following command can view the thread status in a process.

top -H -p pid

Freetop can also view memory, but it is not friendly. Free is specially used to view memory. Including physical memory and virtual memory swap.

The dfdf command is used to check the disk usage in the system, and to check whether the disk has reached the upper limit. Parameter h can be displayed in a friendly way.

DF -h

Ifconfig checks the IP address without verbosity. The alternative is the IP addr command.

Ping as for the network failure, you can use Ping to detect. (excluding websites that are not allowed to Ping)

Although the SS command can replace netstat, netstat is still used more widely in reality. For example, look at all current TCP connections.

Netstat -ant

This command plays a very important role in finding some local ports.

Commonly used in work

There are also some commands that are often used in work. They appear very frequently and are familiar faces A660207 export many students who have installed JDK can’t find the Java command, so export can help you to do it. Export is used to set some environment variables. Env command can see all environment variables in the current system. For example, the following settings are JDK.

export PATH=$PATH:/home/xjj/jdk/bin

Sometimes you want to know the exact path of the command being executed. Then you can use the where is command. I assume you have multiple versions of JDK installed.

Crontab is the local job tool of Linux. It’s not distributed. If it’s not o & M, don’t use it. For example, remind people to drink tea and go to the toilet every 10 minutes.

*/10 * * * * /home/xjj/wc10min

The dateDate command is used to output the current system time. You can use the – S parameter to specify the output format. But setting time involves setting hardware, so there is another command called hwlock.

Xargsxargs reads the input source and processes it line by line. This command is very useful. For example, delete all 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

network

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

SSH, that’s enough. You must want to know what the SSH tunnel is. If you want a detailed output process, remember to add the parameter – V.

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

scp a.txt 192.168.0.12:/tmp/a.txtscp -r a_dir 192.168.0.12:/tmp/

WGet if you want to install JDK on the server, do not download it locally first, and then use SCP to transfer it to the server (sometimes you have to). The WGet command allows you to download files directly from the command line, and supports breakpoint retransmission.

wget -c http://oracle.fuck/jdk2019.bin

MySQL is widely used, not everyone has the condition to use Navicat. You need to understand the connection mode and basic operation of MySQL, so that you can easily handle the abnormal situation.

mysql -u root -p -h 192.168.1.2

End

Don’t feel complicated, the command is limited, but the passion is infinite; don’t be proud, a VIM is enough to toss a lifetime. The short cut is the summary, the thorough only has the exploration. When a white horse passes a gap, he will eventually be caught by hand. Things are different from people. Only time can live up to it.

Linux cloud computing and operation and maintenance architect high paid practical class “will start on July 15, 2019, with an annual salary of 300000 for 120 days, changing the speed~~~~

Leave a Reply

Your email address will not be published. Required fields are marked *