如何使用UNIX命令find搜索在特定日期创建的文件?
当前回答
cp `ls -ltr | grep 'Jun 14' | perl -wne 's/^.*\s+(\S+)$/$1/; print $1 . "\n";'` /some_destination_dir
其他回答
使用此命令搜索“/home/”目录下的文件和文件夹,根据需要增加时间段:
find /home/ -ctime time_period
time_period的示例:
超过30天前:-ctime +30 小于30天前:-ctime -30 正好30天前:-ctime 30
你可以这样做:
find ./ -type f -ls |grep '10 Sep'
例子:
[root@pbx etc]# find /var/ -type f -ls | grep "Dec 24"
791235 4 -rw-r--r-- 1 root root 29 Dec 24 03:24 /var/lib/prelink/full
798227 288 -rw-r--r-- 1 root root 292323 Dec 24 23:53 /var/log/sa/sar24
797244 320 -rw-r--r-- 1 root root 321300 Dec 24 23:50 /var/log/sa/sa24
cp `ls -ltr | grep 'Jun 14' | perl -wne 's/^.*\s+(\S+)$/$1/; print $1 . "\n";'` /some_destination_dir
你不能。-c开关告诉您权限最近一次更改的时间,-a测试最近的访问时间,-m测试修改时间。大多数Linux (ext3)使用的文件系统不支持“创建时间”记录。对不起!
@Max:关于创建时间是正确的。
但是,如果您想为-atime, -ctime, -mtime参数之一计算经过的天数参数,您可以使用以下表达式
ELAPSED_DAYS=$(( ( $(date +%s) - $(date -d '2008-09-24' +%s) ) / 60 / 60 / 24 - 1 ))
将“2008-09-24”替换为您想要的任何日期,ELAPSED_DAYS将被设置为从那时到今天之间的天数。(更新:从结果中减去1以与find的日期舍入对齐。)
因此,要找到2008年9月24日修改的任何文件,命令将是:
find . -type f -mtime $(( ( $(date +%s) - $(date -d '2008-09-24' +%s) ) / 60 / 60 / 24 - 1 ))
如果你的find版本不支持@Arve:的答案中提到的-newerXY谓词,这将有效。