我在工作中通过telnet使用AIX,我想知道如何在日期范围之间查找特定文件夹中的文件.例如:我想查找文件夹X中在01年8月13日到31日 - 8月13日之间创建的所有文件.
观察:
touch一旦我在服务器上的用户角色不允许我创建文件,技巧(你创建两个空文件以使用-newer选项)对我不起作用.cod*_*ard 99
如果你使用GNU find,从版本4.3.3开始,你可以:
find -newerct "1 Aug 2013" ! -newerct "1 Sep 2013" -ls
Run Code Online (Sandbox Code Playgroud)
它将接受GNU接受的任何日期字符串date -d.
您可以将改变c在-newerct任何的a,B,c,或m为寻找的atime /生/的ctime /修改时间.
另一个例子 - 2017年11月6日17:30至22:00之间修改的列表文件:
find -newermt "2017-11-06 17:30:00" ! -newermt "2017-11-06 22:00:00" -ls
Run Code Online (Sandbox Code Playgroud)
详细信息来自man find:
-newerXY reference
Compares the timestamp of the current file with reference. The reference argument is normally the name of a file (and one of its timestamps is used
for the comparison) but it may also be a string describing an absolute time. X and Y are placeholders for other letters, and these letters select
which time belonging to how reference is used for the comparison.
a The access time of the file reference
B The birth time of the file reference
c The inode status change time of reference
m The modification time of the file reference
t reference is interpreted directly as a time
Some combinations are invalid; for example, it is invalid for X to be t. Some combinations are not implemented on all systems; for example B is not
supported on all systems. If an invalid or unsupported combination of XY is specified, a fatal error results. Time specifications are interpreted as
for the argument to the -d option of GNU date. If you try to use the birth time of a reference file, and the birth time cannot be determined, a fatal
error message results. If you specify a test which refers to the birth time of files being examined, this test will fail for any files where the
birth time is unknown.
Run Code Online (Sandbox Code Playgroud)
Jas*_*ski 12
这里有一些好的解决方案.想要分享我的,简而言之.
我正在使用find(GNU findutils)4.5.11
$ find search/path/ -newermt 20130801 \! -newermt 20130831
Run Code Online (Sandbox Code Playgroud)
小智 6
您可以使用以下内容找到您需要的内容.
查找早于特定日期/时间的文件:
find ~/ -mtime $(echo $(date +%s) - $(date +%s -d"Dec 31, 2009 23:59:59") | bc -l | awk '{print $1 / 86400}' | bc -l)
Run Code Online (Sandbox Code Playgroud)
或者您可以在两个日期之间找到文件.第一次约会更近,最后一次约会,更早.你可以下到第二个,你不必使用mtime.你可以随心所欲地使用它.
find . -mtime $(date +%s -d"Aug 10, 2013 23:59:59") -mtime $(date +%s -d"Aug 1, 2013 23:59:59")
Run Code Online (Sandbox Code Playgroud)
使用stat来获取创建时间.您可以按YYYY-MM-DD HH:MM:SS字典顺序比较格式的时间.
这项工作在Linux上具有修改时间,创建时间不受支持.在AIX上,-c可能不支持该选项,但无论如何都应该能够获取信息,grep如果没有其他工作则可以使用.
#! /bin/bash
from='2013-08-01 00:00:00.0000000000' # 01-Aug-13
to='2013-08-31 23:59:59.9999999999' # 31-Aug-13
for file in * ; do
modified=$( stat -c%y "$file" )
if [[ $from < $modified && $modified < $to ]] ; then
echo "$file"
fi
done
Run Code Online (Sandbox Code Playgroud)
小智 5
您可以使用以下命令列出 2 个特定日期之间的文件:
在当前 ( ) 目录中搜索.:
find . -type f -newermt "2019-01-01" ! -newermt "2019-05-01"
Run Code Online (Sandbox Code Playgroud)
在目录上搜索/var/any/directory/:
find /var/any/directory/ -type f -newermt "2019-01-01" ! -newermt "2019-05-01"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
110731 次 |
| 最近记录: |