我在工作中通过telnet使用AIX,我想知道如何在数据范围之间的特定文件夹中查找文件,例如:我想查找在01年8月1日之间创build的文件夹X中的所有文件和2011年8月31日。
观察:
提前致谢!
你可以使用下面的来找到你需要的东西。
查找比特定日期/时间早的文件:
find ~/ -mtime $(echo $(date +%s) - $(date +%s -d"Dec 31, 2009 23:59:59") | bc -l | awk '{print $1 / 86400}' | bc -l)
或者你可以找到两个日期之间的文件。 第一次约会更近,最后约会,更老。 你可以下到第二个,你不必使用mtime。 你可以使用任何你需要的。
find . -mtime $(date +%s -d"Aug 10, 2013 23:59:59") -mtime $(date +%s -d"Aug 1, 2013 23:59:59")
如果你使用GNU find
,从版本4.3.3开始你可以这样做:
find -newerct "1 Aug 2013" ! -newerct "1 Sep 2013" -ls
它将接受GNU date -d
接受的任何日期字符串。
您可以将c
更改为a
, B
, c
或m
任意a
以查看atime / birth / ctime / mtime。
另一个例子 – 列表文件在2017年11月6日17:30至22:00之间修改:
find -newermt "2017-11-06 17:30:00" ! -newermt "2017-11-06 22:00:00" -ls
从man find
全部细节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.
尝试这个:
find /var/tmp -mtime +2 -a -mtime -8 -ls
找到超过2天但不超过8天的文件。
这里有一些很好的解决方案 想要分享我的,以及它简短。
我正在使用find(GNU findutils)4.5.11
$ find search/path/ -newermt 20130801 \! -newermt 20130831
使用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
我试图以更完整的方式回答这个问题,最后我创建了一个完整的脚本,其中包含一些帮助您理解find
命令的选项。
脚本oldfiles
在这个存储库中
要“创建”一个新的查找命令,用-n
(干运行)选项运行它,它会打印出您需要使用的正确的find
命令。
当然,如果你省略了-n
它就会运行,不需要重新输入find
命令。
$ oldfiles [-v...] ([-h|-V|-n] | {[(-a|-u) | (-m|-t) | -c] (-i | -d | -o| -y | -g) N (-\> | -\< | -\=) [-p "pat"]})
-h,–help:显示此帮助。
-V,–version:显示版本。
-v,–verbose:打开详细模式(累计)。
-n,–dry-run:不要运行,只要解释如何创建一个“查找”命令
-a或-u:访问(使用)时间
-m或-t:修改时间(默认)
-c:inode状态更改
-i N:分钟(默认,N等于1分钟)
-d N:天
-o N:几个月
-y N:几年
-g N:N是DATE(例如:“2017-07-06 22:17:15”)
-p“pat”:匹配的可选模式(例如:-p“* .c”查找c文件)(默认-p“*”)
– \>:文件比给定的范围更新,即在它之后修改时间。
– \ <:文件比给定的范围更旧,即时间来自之前。 (默认)
– \ =:正好是N(分,日,月,年)的文件。
$ oldfiles -a -i 10 -p"*.c" -\> -nvvv Starting oldfiles script, by beco, version 20170706.202054... $ oldfiles -vvv -a -i 10 -p "*.c" -\> -n Looking for "*.c" files with (a)ccess time newer than 10 minute(s) find . -name "*.c" -type f -amin -10 -exec ls -ltu --time-style=long-iso {} + Dry-run
$ oldfiles -m -o 1 -p"*.h" -\< -nvv Starting oldfiles script, by beco, version 20170706.202054... $ oldfiles -vv -m -o 1 -p "*.h" -\< -n find . -name "*.h" -type f -mtime +30 -exec ls -lt --time-style=long-iso {} + Dry-run
$ oldfiles -mng "2016-12-01" -\= find . -name "*" -type f -newermt "2016-11-30 23:59:59" ! -newermt "2016-12-01 23:59:59" -exec ls -lt --time-style=long-iso {} +
当然,删除-n
程序会自动运行find
命令并为您节省麻烦。
我希望这能帮助大家最终学习这个{a,c,t}{time,min}
选项。
您还会注意到,“ls”选项会根据您选择的时间类型进行更改。
oldfiles
脚本: