Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

20 commonly used Linux commands in system operation and maintenance

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you the contents of 20 commonly used Linux commands in system operation and maintenance. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1. View directories and permissions

In windows, use dir to view the files in the current directory. Use ls (list) in Linux to view the current directory file.

Dir in windows, as shown in the following figure

In Linux, you usually use ls-l to list, where you can view more detailed information such as file properties, user groups, and so on. The following explains in detail what each column means from left to right

Ls-l

The first field in the first column: file type, and the last nine characters are patterns, which are divided into three groups, each with three fields. The first group is the user rights to which they belong. The second group is the permission of the group to which it belongs. The third group is the permissions of other users. Where r (read) stands for readable, w (write) for writable, and e (execute) for executable. In the next 9 characters, if it is a letter, it indicates that it has the corresponding permission, and if it is "-", it means that it has no permission. Give me an example.

-rw-r-r--: this is a normal file, which is readable and writable for its user, only readable for its group, and only readable for other users.

Number of hard links in the second column

One of the functions of hard links is to allow a file to have multiple valid pathnames, thus preventing erroneous deletion. However, you can only connect between files in the same file system, and you cannot create directories.

The third column is the user, the fourth is the group, the fifth is the file size, the sixth is the time when the file was modified, and the last is the file name. Use chown to change the user and chgrp to change the group.

2. Nohup (no hang up, don't hang up)

This is also a common way to start a program in the background, and if we run the program on the interactive command line, we can easily terminate it. In an interactive environment, our output is usually output directly to the current interface, and is usually directed to a file when launched in the background, which is usually the following command.

Nohup command > X.file 2 > & 1 &

Where 1 represents standard output. 2 represents the file standard error output. 2 > 1 & merge the two, but where to merge is X.file.

3. View the process

Sometimes we need to see if the process has been started or tried to terminate the process. The frequently used command lists the currently running programs for ps-ef---, so how to locate the process A we want to view? use grep, that is, ps-ef | grep A.

4 、 awk

If the file is csv (a.csv), split according to ",", the requirement is to print the first and second columns

Awk-F ","'{print 2} 'a.csv

Get the maximum value of the third column

Awk 'BEGIN {max=0} {if (3} END {print max}'

5. Tars decompress

Extract command

Common parameters

-c: tar file created

-x: unlock the tar file

-t: lists the file information contained in the tar file

-r: attach a new file to the tar file

Common command combination

Tar-xvf / home/a.tar / / Open the tar package file tar-zxvf / home/a.tar.gz / / extract the files compressed with gzip tar-jxvf / home/a.tar.bz2 / / decompress the files compressed with bzip tar-cvf / home/a.tar / home package / all files under home

6 、 scp

Transfer files by copying each other on multiple servers through the scp command. In order to save the input password, you can set a secret-free login.

Common combinations:

Example 1: copy / home/a.txt from server A to / home from server B

Scp-r / home/a.txt root@B_ip:/home

7. Ringo's death order rm-rf

Please read the note at the scene of the rollover.

8 、 watch

This command is the result of dynamically viewing command execution. For example, if you need to highlight changes in the number of network connections every other second. Then watch-n 1-d netstat-ant

Example: highlight the change in the number of http connections every other second

Watch-n 1-d'pstree | grep http'

Example: average load of the output system in ten seconds

Watch-n 10 'cat / proc/loadavg'

9 、 df

View disk siz

Df-h

10 、 tcpdump

A similar tool in windows is wireshark, which is implemented in the underlying library winpcap/libpcap. The bpf filtering mechanism is adopted. Let's take a look at the meaning of the different parameters provided.

The meaning of the parameter name-n uses the IP address to represent the host. Use a number for port-I to specify the port to listen on. If "- I any" represents all network card packets in the residential area-v outputs more detailed information such as TTL in ip packets-t does not print timestamps-e displays Ethernet frame header information-c only crawls a specified number of packets-x displays packet contents in hexadecimal-X not only outputs-x results but also outputs hexadecimal corresponding ASCII characters-s for packet capture Grab packet length-w directs the output to a file Generally, the pcap suffix-r reads the packet from the file and displays the number port-I to specify the port to listen on. If "- I any" represents all network card packets in the residential area-v outputs more detailed information such as TTL in ip packets-t does not print timestamps-e displays Ethernet frame header information-c only crawls a specified number of packets-x displays packet contents in hexadecimal-X not only outputs-x results but also outputs hexadecimal corresponding ASCII characters-s for packet capture Grab packet length-w directs the output to a file Usually read the packet from the file and display it with the pcap suffix-r

Now that we know the relevant parameters, let's look at a few cases.

Execute task execution command capture specific network port packets tcpdump-I eth0 capture specific number of packets tcpdump-c 1000-I eth0 save captured packets to file tcpdump-w a.pcap-I eth0 read packets in pcap format tcpdump-r a.pcap increase the timestamp of capture packets tcpdump-n-ttt-I eth0 specify the protocol type of capture packets tcpdump-I eth0 arp capture specified port tcpdump-I eth0 post 22 capture specific destination Packet tcpdump-I eth0 dst address and port 22 capturing DNS request and response tcpdump-I eth0-s0 port 53 matching Http request header tcpdump-s0-v-n-l | egrep-I "POST / | GET / | Host:" Save the captured packet to a file tcpdump-w a.pcap-I eth0 read the pcap format packet tcpdump-r a.pcap increase the capture packet timestamp tcpdump-n-ttt-I eth0 specify the protocol type tcpdump-I eth0 of the capture packet Arp captures specified port tcpdump-I eth0 post 22 captures packets of specific target ip+port tcpdump-I eth0 dst address and port 22 captures DNS request and response tcpdump-I eth0-s0 port 53 matches Http request header tcpdump-S0-v-n-l | egrep-I "POST / | GET / | Host:"

11 、 lsof

Lists the file descriptor tools currently open by the system. You can know which processes are used by the descriptor of interest

Again, let's look at the relevant parameters

Parameter description-I display sokcet file descriptor-c displays all file descriptors opened by the specified command-t displays only the process pid that has the target file descriptor open

The old rules, the last few examples

Execute task command list all network links lsof-I list all udp network links lsof-I udp list who is using a port lsof-I: 3306 list who is using a specific tcp port lsof-I tcp:80 list file information lsof-d 2-3 according to the file description range

12 、 nc

Nc-- > Swiss Army knife. I don't know if everyone used nc to do something with shell in the process of infiltration. It is used to quickly build web links. It is often used to debug client programs.

Parameter description-I sets the time interval for packet delivery-l runs as a server. The default is for the client to run-k to repeatedly accept and process all links on a port-p to force the client to use the specified port-C to use the characters CR and LF as the Terminator-u using the udp protocol. Default tcp protocol-the Xnc client remaining proxy server defaults to the socks5 protocol when communicating. -z scan whether a range of services on the target machine is enabled

A case of being a little bitch.

Execute task execution command scan machine A port number 30-40 service nc-z A 30-40 connection server A port number 5000nc-C A 5000 transfer file MachineA:nc-v-n ip port

13 、 netstat

Netstat is a network information statistics tool. It can get all the information on the network card interface, routing table information, network card interface information and so on. We usually use it to display TCP connection and status information in network programming.

Parameter description-n uses IP address to represent host-a display result includes monitoring socket-t only shows TCP connection-r displays routing information-I displays Nic interface data traffic-c outputs every 1s-o displays information of socket timer-p displays the PID and name of the process to which socket belongs

Here are a few common examples

Execute task execution command list all connections netstat-a list only TCP or UDPnetstat-at/netstat-au list connections in monitoring netstat-tnl get process name, process number and user IDnestat-nlpt print statistics netstat-snetstat continuously output netstat-ct print active status connection netstat-atnp | grep ESTA check whether the service is running (npt) netstat-aple | grep ntp

14 、 vmstat

Vmstat can output real-time process information, memory usage, cpu usage and other resources of the system.

Parameter description-f displays the number of fork performed by the system since startup-s displays memory-related statistics-d displays disk-related statistics-p displays specified disk partition statistics count samples.

Take a look at what output fields vmstat has.

Insert a picture description here

The field name description procsr represents the number of processes waiting to run. B represents the number of processes in uninterruptible sleep memoryswpd: the amount of virtual memory used. Free: the amount of free memory. Buff: the amount of memory used as a buffer. Cache: the amount of memory used for caching. Swapsi: the amount of memory swapped in from disk (/ s). So: the amount of memory swapped to disk (/ s). Iobi: the blocks/s received from the block device. Bo: the blocks/s sent to the block device. Systemin: number of interrupts per second, including the clock. Cs: the number of context switches per second.

Note here, ha, if you look at the more detailed information of the disk, the confidence gained by iostat is even more detailed.

15 、 mpstat

It can monitor the usage of each cpu in the multiprocessor system in real time. To execute this command, you need to install sysstat. Just execute yum install systat in centos.

Insert a picture description here

Then let's see what each field means.

Field description cpu indicates which cpu the current message belongs to. Data% usr processes running in user space% percentage of cpu running time in user space% time spent in user space running in cpu% time spent waiting for disk operations in cpu% percentage of total cpu running time% irqcpu is used to process hardware interrupt time%% of total cpu running time% softcpu is used for processing software % steal pair of virtual cpu as a percentage of cpu elapsed time. When the Super Admin is working on a virtual cpu, the other waits for it to finish processing before it can run. This wait time is expressed as steal time to total elapsed time% guest running virtual cpu time to total cpu elapsed time% idle system idle time to total cpu elapsed time%

16 、 split

Split the file into several.

Split-5 a.txt// splits a.txt into a file every five lines

17. Wc-c + filename

Count the number of words in the file.

18 、 more/less

Display one page at a time, display the next page / previous page through the blank key

19 、 head/tail

Look at the first or last lines of a file

20 、 diff

Diff-c file1 file2 / / shows the difference between the two files

Thank you for reading! On the "system operation and maintenance of 20 commonly used Linux commands" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report