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

What are the skills that Linux operation and maintenance staff need to master?

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article analyzes "what skills Linux operators need to master". The content is detailed and easy to understand. Friends who are interested in "what skills Linux operation and maintenance need to master" can follow the editor's train of thought to read it in depth. I hope it will be helpful to you after reading. Let's follow the editor to learn more about the skills that Linux operators need to master.

Introduce the skills that linux operation and maintenance need to master.

1. Find all the files ending in .tar in the current directory and move to the specified directory

Find. -name "* .tar"-exec mv {}. / backup/

Note: find-name is mainly used to find a file name,-exec and xargs can be used to undertake the previous results, and then the actions to be performed are generally used with find. Find uses us to extend-mtime to find the modification time,-type is the specified object type (including f for file and d for directory), and-size specifies the size. For example, often used: find the current directory 30 days ago greater than 100m LOG files and delete.

Find. -name "* .log"-mtime + 30-typef-size + 100m | xargs rm-rf {}

2. Batch decompress all files ending with .zip in the current directory to the specified directory.

For i in `find. -name "* .zip"-type f `dounzip-d $I / data/www/img/done

Note: forI in (command); do... Done is a common format of the for loop, where I is a variable and can be specified by yourself.

3. Sed common life collection: test.txt for testing

How to remove the head of the line. Characters:

Sed-i 's / ^. / / g' test.txt

Add an a character at the beginning of the line:

Sed's/ ^ / a Compact g 'test.txt

Add an a character at the end of the line:

Sed's/$/a/' tets.txt

Add a c character after a specific line

Sed'/ wuguangke/ac' test.txt

Add a c character before the line

Sed'/wuguangke/ic' test.txt

Please refer to the documentation for more sed commands.

4, how to judge whether a directory exists, if it does not exist, it will be newly built, and if it exists, the information will be printed.

If [!-d / data/backup/]; thenMkdir-p / data/backup/elseecho "The Directory alreadyexists,please exit" fi

Note: if... ; then... Else.. fi: for if conditional statement,! An exclamation mark means "does not exist", and-d represents a directory.

5. Monitor the root partition of linux disk. If the root partition space is greater than or equal to 90%, send email to Linux SA.

(1) print root partition size

Df-h | sed-n'/ / $/ p' | awk'{print $5}'| awk-F "%"'{print $1}'

Note: awk'{print $5} 'means to print the fifth field,-F means to separate, for example, separated by%, simply means to remove the percent sign, awk-F.' {print $1} 'separation point. No.

(2) the if condition determines whether the size is greater than 90, and sends an email alarm if it is greater than 90.

While sleep 5mdofor I in `thenecho-h | sed-n'/ / $/ p' | awk'{print $5}'| sed's Linux of disk space% doecho $iif [$I-ge 90]; thenecho "More than 90% Linux of disk space, Please LinuxSA Check Linux Disk!" | mail-s "Warn Linux / Parts is $I%" XXX@XXX.XXfidonedone

6. Count the Nginx access log, and the top 20 ip addresses in terms of traffic

Cat access.log | awk'{print $1}'| sort | uniq-c | sort-nr | head-20

Comments: sort sorting, uniq (check and delete repeated rows in text files)

7. Another use of sed finds the current line, and then modifies the parameters after the line

Sed-I'/ SELINUX/s/enforcing/disabled/' / etc/selinux/config

The Sed colon sed-I 's:/tmp:/tmp/abc/:g'test.txt means to change / tmp to / tmp/abc/.

8. Print out the maximum and minimum values in a file

Cat a.txt | sort-nr | awk'{} END {print} NR==1'cat a.txt | sort-nr | awk 'END {print} NR==1'

This is the real maximum and minimum value of printing: sed's / / / g 'a.txt | sort-nr | sed-n' 1p

9. Use snmpd to grab cacti data of version v2.

Snmpwalk-V2C-c public 192.168.0.241

10. Modify the text ending with jk and replace it with yz

Sed-e's Universe JKG b.txt

11. Network packet capture: tcpdump

Tcpdump-nn host 192.168.56.7 and port 80 crawls packets requested by 56.7 through 80. Tcpdump-nn host 192.168.56.7 or! Host 192.168.0.22 and port 80 excludes port 0.22 80! Tcp/ip layer 7 protocol physical layer-data link layer-network layer-transport layer-session layer-presentation layer-application layer.

12. Show the 20 most commonly used commands

Cat .bash _ history | grep-v ^ # | awk'{print $1}'| sort | uniq-c | sort-nr | head-20

13. Write a script to find files that were last created 3 days ago with the suffix * .log and delete them.

Find. -mtime + 3-name "* .log" | xargs rm-rf {}

14. Write a script to move files greater than 100k in a directory to / tmp.

Find. -size + 100k-exec mv {} / tmp

15. Write a firewall configuration script that only allows remote hosts to access port 80 of the machine.

Iptables-Fiptables-Xiptables-An INPUT-p tcp-- dport 80-j acceptiptables-An INPUT-p tcp-j REJECT or iptables-An INPUT-m state-- state NEW-m tcp-p tcp-- dport 80-j ACCEPT

16. Write a script for nginx log statistics, and get the top 10 access to ip (nginx log path)

/ home/logs/nginx/default/access.log).

Cd / home/logs.nginx/defaultsort-m-k 4-o access.logok access.1 access.2 access.3 .cat access.logok | awk'{print $1}'| sort-n | uniq-c | sort-nr | head-10

17. Replace the directory in the file

Sed's Linux test.txt user _ test.txt _ test.txt or TMP _ test.txt _ sed-I's _ skills that need to be mastered by Linux operation and maintenance staff will be shared here. I hope the above content can help you improve. If you want to learn more knowledge, please pay more attention to the editor's updates. Thank you for following the website!

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

Development

Wechat

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

12
Report