Redhat Shell脚本显示最近5天内修改的文件数量:

huangapple go评论76阅读模式
英文:

Redhat Shellscript Displaying "count" of files modified in the last 5 days

问题

我正在尝试显示最近5天保存/修改的文件数量。换句话说,我只需要知道5天前消息的数量。

我在谷歌上搜索到,它提到了使用 find 命令。

但我想使用 ls 命令。
我可以使用 ls | wc -l 进行计数,但这并不排除/过滤掉根据文件的修改时间进行筛选的文件。

我尝试过 -mtime +5-ctime +5 但仍然无法得到正确的结果。

谢谢。

英文:

I am trying to display the count/number of files that was saved/modified last 5 days. In other words, I just need to know the count of 5-day old messages.

I searched google and it talks about using find

For me, I would like to use ls command.
I am able to count using ls | wc -l but that does not exclude/filter files by age(last modified)

I tried -mtime +5 or -ctime +5 but still can't get it right.

Thank you.

答案1

得分: 0

如果你想查找在过去5天内修改过的文件数(理解为过去120小时),从根目录/开始,我会尝试以下命令:

find / -type f -mtime -5 | wc -l

命令wc -l用于计算输出的行数。错误消息不包括在内。

如果你想将搜索限制在树结构的某个部分,比如你的$HOME目录,请将/改为$HOME

如果你的树结构中包含符号链接,你需要在find命令中添加一些选项,比如-L

英文:

If you want to find the count of files modified in the last 5 days (understood as last 120 hours) starting from the root directory /, I would try:

find / -type f -mtime -5 | wc -l

The command wc -l counts the number of lines of output. Error messages are not included in that count.

If you want to limit your search to a part of the tree structure, v.gr. your $HOME directory, change / by $HOME.

If you have symlinks in your tree structure, you will need to add some options like -L to the find command

huangapple
  • 本文由 发表于 2023年3月9日 21:58:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/75685605.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定