如何查找带有前缀日期的文件然后是gzip

时间:2019-05-03 16:25:10

标签: linux find gzip

使用tar做到这一点很简单:

 date=`date +%F-%T`;find /var/log/nginx -name "access.log" -mtime -1 -type f -print | xargs -0 tar czvf /tmp/$date-access.tar.gz

$ ls /tmp
2019-05-03-11:25:49-access.tar.gz

我该如何使用gzip?

1 个答案:

答案 0 :(得分:2)

find + bash + gzip解决方案:

$ d=$(date +%F-%T)
$ find /var/log/nginx -name "access.log" -mtime -1 -type f \
-exec bash -c 'gzip -c "$2" > "/tmp/$1-access.gz"' _ $d {} \;
相关问题