【问题标题】:AIX - how to list files of today's dateAIX - 如何列出今天日期的文件
【发布时间】:2021-09-12 22:14:52
【问题描述】:

在 AIX 中列出今天日期目录中的文件的命令是什么?来自 Unix 和 Linux 的命令并非都适用于 AIX。

【问题讨论】:

  • find directory -type f -mtime 0 有什么问题?
  • 请注意,文件日期存储为 unix 时间戳,因此“今天”的含义取决于您的时区;例如,该文件可能是在澳大利亚的 2021-07-02 创建的,而我的时区是 2021-07-01。
  • @Darkman — 有关-mtime 工作原理的描述,请参阅Explaining the find -mtime command(基于 POSIX;也许应该是“-mtime 应该如何工作”),因此您可以弄清楚是什么错误使用find directory -type f -mtime 0。 TL;DR — -mtime 0 表示“过去 24 小时内”,而不是“从当地时间午夜开始计算的当天”(这是我认为 OP 想要的)。
  • @JonathanLeffler - 是的,我知道。我只是想知道 “并非所有都在 AIX 中工作。” 的 OP 是什么意思。 OP想要的可能是:find directory -type f -daystart -ctime 0
  • 在 macOS 上使用 -daystart 不起作用????很遗憾。它也不适用于 AIX。根据 AIX 7.2 上 find 的手册页,它支持条件 -amin-atime-cmin-cpio-ctime-depth-ea-follow-fstype-group-inum-links-iregex-long-ls-mmin-mtime-name-newer-nogroup-nouser-perm-size-regex-regextype-size-type-user-xdev。使用-newer 可能是最好的选择。如answer所示。

标签: shell file aix


【解决方案1】:

从 Stéphane Chazelas 的 a POSIX solution at U&L to a similar problem 获得灵感,这将递归地在 /path/to/directory 下找到 文件 (-type f),其修改时间为今天的日期(从午夜):

touch -t "$(date +%Y%m%d0000)" ~/.today &&
  find /path/to/directory -type f -newer ~/.today
rm ~/.today

...当然,您将 ~/.today 时间戳文件放在 /path/to/directory 之外的位置。

或者,AIX Toolbox for Linux Applications 站点已打包 zsh 及其依赖项,因此您可以下载并安装它们,然后将 "age" function 用作 glob qualifier

zsh
autoload age
print -- /path/to/directory/*(.e:age today:)    ## non-recursive
print -- /path/to/directory/**/*(.e:age today:) ## recursive

glob 限定符中的. 将匹配限制为文件; e: ...: 创建一个表达式,每个文件调用该表达式以确定包含/排除。

再次感谢 Stéphane 在this U&L answer 中演示年龄函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-31
    • 1970-01-01
    • 2018-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多