bash 调试:
bash -x install.sh
 
常用命令:
grep 匹配单词:
dpkg -l | grep -w git #查找包含git单词的字符-w, --word-regexp
ps -ef | grep -w agent | grep -v grep #查找包含agent的进程
 
记录:sed 先搜索后替换,逗号分割
sed -i '/iface eth2/,/eth2/ s/eth2/eth3/g' ./interfaces #替换指定行内容
 
批量操作:
ls *.tar.gz | xargs -n1 tar xzvf // n1 数字1
for tar in *.tar.gz; do tar xvf $tar; done
for IP in {20..50}; do ping -c 2 "172.21.130."$IP; done;
 
操作文件
删除多个文件
rm -rf step.{11..37}
删除其它文件:
rm -rf !(step.1)
rm -rf !(step.1 | step.2)
创建多个文件
touch a{1..5}.txt
批量拷贝文件:
find ./ -name "*.pdf" | xargs -i -t cp {} ../lats-doc/
批量修改文件内容:
grep -rl "root" ./* | xargs sed -i 's/root/audadmin/g'
获取文件全路径
[root@localhost conf.d]# readlink -f health_alarm_notify.conf
/etc/netdata/conf.d/health_alarm_notify.conf
 
=========================while-if=======================
#!/bin/bash
i=50
while [ $i -gt 1 ]
do
        let i--
        if [ $i -eq 10 ]; then
                echo "i is $i if continue"
                continue
        elif [ $i -le 5 ]; then
                echo "i is $i elif break"
                break
        fi
        echo "$i"
                
done

 

posted on 2023-02-23 15:21  天外来客I  阅读(29)  评论(0)    收藏  举报