Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.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
Linux 查找在日期范围之间创建的文件_Linux_Find_Aix - Fatal编程技术网

Linux 查找在日期范围之间创建的文件

Linux 查找在日期范围之间创建的文件,linux,find,aix,Linux,Find,Aix,我在工作中通过telnet使用AIX,我想知道如何在日期范围之间的特定文件夹中查找文件。例如:我想查找文件夹X中2013年8月1日至2013年8月31日之间创建的所有文件 意见: 当服务器上的用户角色不允许我创建文件时,touch技巧(创建两个空文件以使用-newer选项)对我不起作用 我需要在特定日期之间查找,而不是几天(例如:30天前创建的文件,等等) 使用stat获取创建时间。您可以按字典顺序比较格式为YYYY-MM-DD HH:MM:SS的时间 这项工作在Linux上需要修改时间,不支

我在工作中通过telnet使用AIX,我想知道如何在日期范围之间的特定文件夹中查找文件。例如:我想查找文件夹X中2013年8月1日至2013年8月31日之间创建的所有文件

意见:

  • 当服务器上的用户角色不允许我创建文件时,
    touch
    技巧(创建两个空文件以使用-newer选项)对我不起作用
  • 我需要在特定日期之间查找,而不是几天(例如:30天前创建的文件,等等)

使用
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
#/bin/bash
自2013年8月1日00:00:00.0000000000起
致:2013-08-3123:59:59.9999999'#2013年8月31日
以*存档;做
修改=$(统计-c%y“$文件”)
如果[[$from<$modified&$modified<$to]];然后
回显“$file”
fi
完成

您可以使用下面的内容查找所需内容

find . -mtime $(date +%s -d"Aug 10, 2013 23:59:59") -mtime $(date +%s -d"Aug 1, 2013 23:59:59")
查找早于特定日期/时间的文件:

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

您可以将
-newerct
中的
c
更改为
a
B
c
m
中的任意一个,以查看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
来自
人工查找的完整详细信息

   -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
命令

脚本
oldfiles
位于此

要“创建”一个新的find命令,您可以使用选项
-n
(干运行)运行它,它将向您打印您需要使用的正确的
find
命令

当然,如果省略
-n
,它将只运行,无需重新键入
find
命令

用法:
$oldfiles[-v..]([-h |-v |-n]{[-a |-u)|(-m |-t)|-c](-i |-d |-o |-y |-g)n(\>-\\\<\\\==)[-p“pat”}/code>

  • 其中选项分为以下几组:
    • 帮助和信息: -h、 --帮助:显示此帮助。
      -五、 --版本:显示版本。
      -v、 --详细:打开详细模式(累积)。
      -n、 --干运行:不要运行,只是解释如何创建“find”命令

    • 时间类型(访问/使用、修改时间或更改状态): -a或-u:访问(使用)时间
      -m或-t:修改时间(默认值)
      -c:索引节点状态更改

    • 时间范围(其中N为正整数): -i N:分钟(默认值,N等于1分钟)
      -d N:天
      -否:月份
      -年:年
      -N是一个日期(例如:“2017-07-06 22:17:15”)

    • 测试: -p“pat”:要匹配的可选模式(例如:-p“*.c”查找c文件)(默认值-p“*”)
      -\>:文件比给定的范围更新,即在它之后修改的时间。
      -\<:文件早于给定范围,即时间早于给定范围。(默认值)
      -\=:正好是N(分钟、天、月、年)的文件

例子:
  • 查找10分钟(访问时间)以上的C源文件(详细程度为3):

$oldfiles-a-i10-p“*.c”-\>-nvv
正在启动beco的oldfiles脚本,版本20170706.202054。。。
$oldfiles-vvv-a-i10-p“*.c”-\>-n
正在查找访问时间大于10分钟的“*.c”文件
找到-name“*.c”-type f-amin-10-exec ls-ltu--time style=long iso{}+
试运行

  • 查找早于一个月(修改时间)的H头文件(详细信息2):

$oldfiles-m-o 1-p“*.h”-\<-nvv
正在启动beco的oldfiles脚本,版本20170706.202054。。。
$oldfiles-vv-m-o 1-p“*.h”-\<-n
找到-名称“*.h”-类型f-mtime+30-exec ls-lt--time style=long iso{}+
试运行

  • 在一天内查找所有(*)文件(2016年12月1日;无冗余,干运行):

$oldfiles-mng“2016-12-01”-\=
找到-名称“*”-类型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输出: 您还会注意到“ls”选项
ls OPT
会根据您选择的时间类型进行更改

用于克隆/下载
旧文件
脚本的链接:

说明:使用unix命令
查找
,并带有
-ctime
(创建时间)标志

find实用程序递归地为列出的每个路径下放到目录树中,根据树中的每个文件计算表达式(由“primary”和“operans”组成)

Sol
-ctime n[smhdw]
             If no units are specified, this primary evaluates to true if the difference
             between the time of last change of file status information and the time find
             was started, rounded up to the next full 24-hour period, is n 24-hour peri-
             ods.

             If units are specified, this primary evaluates to true if the difference
             between the time of last change of file status information and the time find
             was started is exactly n units.  Please refer to the -atime primary descrip-
             tion for information on supported time units.