天天看點

日志切割操作1. 查找檔案所在行數2. 檔案所有行數3. 擷取從最後面到中間的數值4. 切割5.打包删除7天前檔案

1. 查找檔案所在行數

sed -n '/字元串/=' file
##sed -n '/取值/=' aa.log           

2. 檔案所有行數

wc -l file
## wc -l aa.log           

3. 擷取從最後面到中間的數值

tail -n number file > file2
### 總行數-檔案所在行數=所需A-B行數
##取值中間到前面
head -n number file > file2
## C-D的值=取到的值           

4. 切割

split -b 100M -d file file_
##基于第三部拿到的檔案
split -b 100M -d 拿到的檔案 命名
for i in `ls *_*`
> do
>    mv $i $i\.log
> done
##加上檔案尾椎.log           

5.打包

tar -zcvf 命名.tar.gz jpush_0*

删除7天前檔案

find /data/backpack/showdoc -type f -name "*tar.gz" -ctime +7 | xargs rm -f