Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Date 查找两个日期之间的文件_Date_Unix_Datetime_Awk_Ls - Fatal编程技术网

Date 查找两个日期之间的文件

Date 查找两个日期之间的文件,date,unix,datetime,awk,ls,Date,Unix,Datetime,Awk,Ls,我想用以下格式获取2个日期之间的所有文件:YYYY-MM-DD HH:MM 我也有一些限制:我甚至不能在/tmp中编写文件,也不能使用find-newermt,因为它是一个旧服务器 我尝试使用awk但没有成功: ls -l --time-style=long-iso | awk '{ if (mktime(gensub ("-", " ", $6) " " gensub (":", " ", $7) " 00") >= mktime(gensub ("-", " ", gensub ("

我想用以下格式获取2个日期之间的所有文件:YYYY-MM-DD HH:MM

我也有一些限制:我甚至不能在/tmp中编写文件,也不能使用find-newermt,因为它是一个旧服务器

我尝试使用awk但没有成功:

ls -l  --time-style=long-iso | awk '{ if (mktime(gensub ("-", " ", $6) " " gensub (":", " ", $7) " 00") >= mktime(gensub ("-", " ", gensub (":", " ", "2014-08-26 12:30")) " 00") && mktime(gensub ("-", " ", $6) " " gensub (":", " ", $7) " 00") <= mktime(gensub ("-", " ", gensub (":", " ", "2014-08-26 12:30")) " 00")) print $8 }'

提前谢谢

你的意思是说有一个旧版本的“find”还是说你根本没有“find”

如果您确实找到了,但它是一个旧版本,那么除了'-newermt',还有另一种方法:

第三个答案显示了如何创建两个具有所需时间戳的文件。然后使用:

find / -newer /tmp/t1 -and -not -newer /tmp/t2
我想看看你能不能用一个合适的格式来使用stat。在我的linux系统上,用

stat --format=$'%n\t%y' *
然后,根据mtime进行过滤:

stat --format=$'%n\t%y' * |
awk -F"\t" -v from="2014-08-01 00:00" \
           -v to="2014-09-01 00:00"   'from <= $NF && $NF <= to {NF--; print}'

您正在尝试匹配具有yyyy-mm-dd格式的文件名?或者文件的mtime/atime/ctime?很抱歉忘记,它的mtime/atime/ctime文件有一个旧版本的find。但我不能写文件,因为我只有阅读权限。这是一家大公司的prod服务器,所以我无法制作我想要的:/