当前位置:网站首页>Common UNIX Operation and maintenance commands of shell
Common UNIX Operation and maintenance commands of shell
2022-07-01 04:38:00 【Moshow Zhengkai】
1、 Find all in the directory to .zip The last file is moved to the specified directory .
find . -name “*.zip” -exec mv {} ./backup/ ;
2、 Find the current directory 30 Days ago, it was greater than 100M Of log File and delete .
find . -name “*.log” –mtime +30 –typef –size +100M | xargs rm –rf {};
3、 Batch decompress the current directory to .zip At the end of all the files to the specified directory .
for i in
find . –name "*.zip" –type f
do
unzip –d $i /data/www/
done
annotation :for i in (command);do … done by for A common format for loops , among i As a variable , You can specify that .
4、 Write a script to find the last creation time is 3 Days ago, , Suffix is *.log And delete .
find . -mtime +3 -name “*.log” | xargs rm -rf {};
5、 Write a script to make a directory larger than 100k Move your file to /tmp Next
find . -size +100k -exec mv {} /tmp;
6、 How to determine whether a directory exists , If it doesn't exist, create a new one , Print information if it exists .
if [ ! –d /data/backup/ ];then
mkdir –p /data/backup/
else
echo “ directory already exists ”
fi
-d Representative directory
7、 Replace the directory in the file
sed ‘s:/usr/local:/tmp:g’ test.txt
perhaps
sed -i ‘s//usr/local//tmp/g’ test.txt
8、sed Common commands
How to get rid of the beginning . character :
sed -i ‘s/^.//g’ test.txt
Add a... At the beginning of the line a character :
sed ‘s/^/a/g’ test.txt
Add a... At the end of the line a character :
sed ‘s/$/a/’ tets.txt
Add a... After a specific line z character :
sed ‘/rumen/az’ test.txt
Add a c character :
sed ‘/rumenz/ic’ test.txt
9、sed Another usage is to find the current line , Then modify the parameters after the line
sed -i ‘/SELINUX/s/enforcing/disabled/’ /etc/selinux/config
sed Colon mode , It means that /tmp Change to /tmp/abc/.
sed -i ‘s:/tmp:/tmp/abc/:g’ test.txt
10、 Statistics Nginx Access log Top of the list of visits 20 Of ip Address
cat access.log |awk ‘{print $1}’|sort|uniq -c |sort -nr |head -20
annotation :sort Sort 、uniq( Check and delete the repeated rows and columns in the text file )
11、 Modify the text to ab Replace the ending with cd:
sed -e ‘s/ab$/cd/g’ b.txt
12、 Network packet capture :tcpdump
# Grab 56.7 adopt 80 Packets requested by the port .
tcpdump -nn host 192.168.56.7 and port 80
# exclude 0.22 80 port
tcpdump -nn host 192.168.56.7 or ! host 192.168.0.22 and port 80
13、 Statistics bash_history Most commonly used 20 Bar command
history | awk ‘{print $2}’ | sort | uniq -c | sort -k1,1nr | head -10
14、 Configure firewall scripts , Only remote hosts are allowed to access local 80 port
iptables -F
iptables -X
iptables -A INPUT -p tcp --dport 80 -j accept
iptables -A INPUT -p tcp -j REJECT
perhaps
iptables -A INPUT -m state --state NEW-m tcp -p tcp --dport 80 -j ACCEPT
边栏推荐
- Web server: how to choose a good web server these five aspects should be paid attention to
- Do280 management application deployment --rc
- Leetcode learning - day 36
- JS rotation chart
- LM小型可编程控制器软件(基于CoDeSys)笔记十九:报错does not match the profile of the target
- Caijing 365 stock internal reference | the first IPO of Beijing stock exchange; the subsidiary of the recommended securities firm for gambling and gambling, with a 40% discount
- Haskell lightweight threads overhead and use on multicores
- Hololens2 development environment building and deploying apps
- 2022 G2 power station boiler stoker examination question bank and G2 power station boiler stoker simulation examination question bank
- Ospfb notes - five messages [ultra detailed] [Hello message, DD message, LSR message, LSU message, lsack message]
猜你喜欢

Annual inventory review of Alibaba cloud's observable practices in 2021

Class and object finalization
![[send email with error] 535 error:authentication failed](/img/58/8cd22fed1557077994cd78fd29f596.png)
[send email with error] 535 error:authentication failed

Recommend the best product development process in the Internet industry!
![[learn C and fly] S1E20: two dimensional array](/img/68/34fad73ff23d3e0719ef364fc60cb5.jpg)
[learn C and fly] S1E20: two dimensional array

Programs and processes, process management, foreground and background processes
![[godot] unity's animator is different from Godot's animplayer](/img/51/48f40a7b6736d7f78040eabbbd3395.jpg)
[godot] unity's animator is different from Godot's animplayer

离线安装wireshark2.6.10
![[leetcode skimming] February summary (updating)](/img/62/0d0d9f11434e49d33754a2e4f2ea65.jpg)
[leetcode skimming] February summary (updating)

Knowledge supplement: redis' basic data types and corresponding commands
随机推荐
MySQL winter vacation self-study 2022 12 (5)
Unity's 3D multi-point arrow navigation
Knowledge supplement: basic usage of redis based on docker
Why is Hong Kong server most suitable for overseas website construction
Offline installation of Wireshark 2.6.10
283. move zero
CUDA development and debugging tool
MySQL advanced -- you will have a new understanding of MySQL
2022年煤气考试题库及在线模拟考试
Execution failed for task ‘:app:processDebugResources‘. > A failure occurred while executing com. and
2. Use of classlist (element class name)
Task04 | statistiques mathématiques
OdeInt与GPU
2022年化工自动化控制仪表操作证考试题库及答案
Some small knowledge points
After many job hopping, the monthly salary is equal to the annual salary of old colleagues
为什么香港服务器最适合海外建站使用
[untitled]
Section 27 remote access virtual private network workflow and experimental demonstration
Coinbase in a bear market: losses, layoffs, stock price plunges