一.常用Linux命令
1.1简单命令
ls pwd mkdir(mkdir -p) cd cp (cp -r) ps (ps -ef) cat less vim grep
du -sh
df
tail -f
1.2复杂命令
1.ps -ef | grep "service" | awk '{print $2}' | xargs rm -rf (杀掉查询出来的所有服务)
2.scp /home/work/ruxiaoqiang.txt [email protected]/home/work (跨服务器之间进行cp)
3.find ./ -name "*logs" 查询当前目录下所有带logs的路径
4.ls /home/work | wc -l (获取/home/work下的目录数)
二.简单shell脚本的编写
1.清理日志脚本
#获取保存日期
time1=#(date "+%Y%m%d")
time2=#(date -d"1 day ago" +%Y%m%d)
logs_dir="/home/work/logs"
#获取logs所在的路径
logsList=`find ${logs_dir} -name "*logs"`
for logItem in $logsList
do
if test -d $logItem
then
logList=`ls $logItem | grep -v $time1 | grep -v $time2 `
for logI in $logList
do
if test -d $logItem/$logI
then
rm -rf $logItem/$logI
fi
done
fi
done
标签:grep,logs,work,常用命令,logItem,linux,home,cp From: https://www.cnblogs.com/ruxiaoqiang/p/16944067.html