In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "what practical skills need to be mastered by Linux operation and maintenance". In daily operation, I believe that many people have doubts about the practical skills that Linux operation and maintenance need to master. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what practical skills Linux operation and maintenance need to master". Next, please follow the editor to study!
1. Find all 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 `do unzip-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. Character: sed-i 's / ^. / / g 'test.txt add an a character at the beginning of the line: sed's/ ^ / a sed's/$/a/' tets.txt g' test.txt adds an a character at the end of the line: sed's/$/a/' tets.txt adds a c character after a specific line: sed'/wuguangke/ ac' test.txt adds 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/]; then Mkdir-p / data/backup/ else echo "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 5m do for i in `then echo-h | sed-n'/ / $/ p' | awk'{print $5}'| sed's Linux of disk space% do echo $I if [$I-ge 90]; then echo "More than 90% Linux of disk space, Please LinuxSA Check Linux Disk!" | mail-s "Warn Linux / Parts is $I%" XXX@XXX.XX fi done done
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 usage 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 print maximum and minimum value:
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
Grab 56.7 packets requested through 80.
Tcpdump-nn host 192.168.56.7 or! Host 192.168.0.22 and port 80
Exclude 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. Display 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-F iptables-X iptables-An INPUT-p tcp-- dport 80-j accept iptables-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 visits to ip (nginx log path:
/ home/logs/nginx/default/access.log). Cd / home/logs.nginx/default sort-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 VuGR test.txt UserUserUserUserLog UserVERGULAR
Or
This is the end of sed-I's Linux test.txt, hoping to solve everyone's doubts about what practical skills Linux operators need to master. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.