linux 目录下文件批量植入和删除,按日期打包

linux目录下文件批量植入

[root@greymouster http2]# find /usr/local/http2/htdocs/ -type f|xargs sed -i "1  i <script>alert(1)</script>"

其中上面的1 为文件的第一行 i为植入

批量删除:

[root@greymouster ~]# find /usr/local/http2/htdocs/ -type f|xargs sed -i '/<script>alert(1)</script>/d'

[root@greymouster htdocs]# find /usr/local/http2/htdocs/ -type f -exec sed -i "/<script>alert(1)</script>/d" {} ;

 批量替换

[root@greymouster ~]# find /usr/local/http2/htdocs/ -type f|xargs sed -i 's#<script>alert(1)</script>#1111#g

打印三天前的日期格式

[root@greymouster htdocs]# date +%F -d "3 day ago" 

[root@greymouster htdocs]# date +%F --date "3 day ago"

[root@greymouster htdocs]# date +%F -d "-3 day"

打印明天的日期格式

[root@greymouster htdocs]# date +%F -d "next day"

打印三天后的日期格式

[root@greymouster htdocs]# date +%F -d "+3 day"

注:-d  相当于 --date 

六分钟前的时间格式

[root@greymouster htdocs]# date +%Y%m%d%H%M -d '-6 min'

按日期格式打包

[root@greymouster htdocs]# tar zcvf text-$(date +%F -d '-3 day').tar.gz ./a.php
./a.php
[root@greymouster htdocs]# ls
a.php index.html index.php text-2016-12-18.tar.gz

把文件中的空行过滤掉

grep方法

[root@greymouster htdocs]# grep -v "^$"   a.text

sed 方法

[root@greymouster htdocs]# sed '/^$/d'    a.text

awk 方法

[root@greymouster htdocs]# awk /^[^$]/   a.text

把文件中的空行删除

[root@greymouster htdocs]# find a.text|xargs sed -i '/^$/d' 

原文地址:https://www.cnblogs.com/chenchenphp/p/6195880.html