简体   繁体   English

Linux - 有没有办法获取目录的文件大小,但只包括最后修改/创建日期为 x 的文件?

[英]Linux - is there a way to get the file size of a directory BUT only including the files that have a last modified / creation date of x?

as per title I am trying to find a way to get the file size of a directory (using du) but only counting the files in the directory that have been created (or modified) after a specific date.根据标题,我试图找到一种方法来获取目录的文件大小(使用 du),但只计算在特定日期之后创建(或修改)的目录中的文件。

Is it something that can be done using the command line?是否可以使用命令行完成?

Thanks:)谢谢:)

From @Bodo's comment.来自@Bodo 的评论。 Using GNU find:使用 GNU 查找:

find directory/ -type f -newermt 2021-11-25 -printf "%s\t %f\n" | \
awk '{s += $1 } END { print s }' | \
numfmt --to=iec-i
  1. find looks in in directory/ ( change this ) finddirectory/中查找(更改此内容
  2. Looks for files ( -type f )查找文件 ( -type f )
  3. that have a newer modified time than 2021-11-25 ( -newermt ) ( change this ) 修改时间比 2021-11-25 ( -newermt ) 更新的 (更改此)
  4. and outputs the files's size ( %s ) on each line并在每一行输出文件的大小( %s
  5. adds up all the sizes from the lines with awk {s += $1 }将所有尺寸与awk {s += $1 }
  6. Prints the results END { print s }打印结果END { print s }
  7. Formats the byte value to human readable with numfmt 's --to=iec-i使用numfmt--to=iec-i将字节值格式化为人类可读

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM