查找与特定大小和修改时间匹配的文件?

查找与特定大小和修改时间匹配的文件?

如何查找目录中大于特定大小(例如 15 KB)且在过去 10 天内修改过的所有文件?

答案1

我会这样做:

find /directory -mtime -10 -size +15k

/directory执行搜索的基本目录(默认情况下递归)。

-mtime 10意味着它将查找最近 10 天内修改的文件:

  -mtime n
          File's data was last modified n*24 hours ago.  See the comments for -atime to understand how rounding affects the interpretation of file modi-
          fication times.

-size 15k意味着它将查找大于 15 KB 的文件:

  -size n[cwbkMG]
          File uses n units of space, rounding up.  The following suffixes
          can be used:

          `b'    for 512-byte blocks (this is the default if no suffix is used)
          `c'    for bytes
          `w'    for two-byte words
          `k'    for Kilobytes (units of 1024 bytes)
          `M'    for Megabytes (units of 1048576 bytes)
          `G'    for Gigabytes (units of 1073741824 bytes)

          The  size  does  not  count  indirect  blocks, but it does count
          blocks in sparse files that are not actually allocated.  Bear in
          mind  that the `%k' and `%b' format specifiers of -printf handle
          sparse  files  differently.   The  `b'  suffix  always   denotes
          512-byte  blocks and never 1 Kilobyte blocks, which is different
          to the behaviour of -ls.  The + and - prefixes  signify  greater
          than  and less than, as usual, but bear in mind that the size is
          rounded up to the next unit (so a 1-byte file is not matched  by
          -size -1M).

如果这是某种家庭作业问题,请find(1)通过键入man find您的系统来阅读操作系统手册,并真正了解它是如何工作的。

答案2

因为我知道新手很难找出可以使用哪个 Linux 命令来获得特定结果,所以我会为您指出正确的方向。

您需要使用的命令是find.它的手册页,您可以通过以下方式阅读

man find

将为您提供所需的所有信息。从这时起你就可以单独工作了。

相关内容