是否有可能通过的确切日期查找文件,然后对结果文件执行tar命令? [英] Is it possible to find files by the exact date then execute tar command on the results files?

查看:169
本文介绍了是否有可能通过的确切日期查找文件,然后对结果文件执行tar命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过具体的日期来搜索文件,然后对结果文件执行tar命令。

例如:

  -RW-RW-R-- 1 0 12月4日8时07分文件1
-rw-RW-R-- 1 0 12月4日08:07文件2
-rw-RW-R-- 1 0 12月5日08:07文件3

我想只得到文件,12月4日的日期,并将其传递给tar命令。

归档应包含:

 焦油-ztvf dec4.tar.gz

输出:

  -RW-RW-R-- 1 0 12月4日08:07文件1
-rw-RW-R-- 1 0 12月4日08:07文件2

这是我的脚本它仍然是复制的12月5日。

LS -ltr ./ | grep的12月4日|焦油-zcvf /家庭/ backupfiles _ $(日期'+%Y_%M_%D'--date ='1天前')。的tar.gz


解决方案

 与stat -c%Z; N* | grep'可以^ 2012年12月4日| awk的-F; {打印$ 2}'| xargs的焦油-zcvf dec4.tar.gz

I want to search for files by the exact date and then execute tar command on the results files.

Example:

-rw-rw-r--  1      0 Dec  4 08:07 file-1
-rw-rw-r--  1      0 Dec  4 08:07 file-2
-rw-rw-r--  1      0 Dec  5 08:07 file-3

I want to get only files with Dec 4 date and passing them to the tar command.

The archive should contain:

tar -ztvf dec4.tar.gz

Output:

-rw-rw-r--  1      0 Dec  4 08:07 file-1
-rw-rw-r--  1      0 Dec  4 08:07 file-2

This is my script it is still copying those Dec 5.

ls -ltr ./ | grep "Dec 4" | tar -zcvf /home/backupfiles_$(date '+%Y_%m_%d' --date='1 days ago').tar.gz

解决方案

stat -c"%z;%n" * | grep '^2012-12-04' | awk -F';' '{ print $2 }' | xargs tar -zcvf dec4.tar.gz

这篇关于是否有可能通过的确切日期查找文件,然后对结果文件执行tar命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆