Linux 获取上个月修改的文件数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9738721/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:13:25  来源:igfitidea点击:

get number of files modified last month

linuxbashshell

提问by Webnet

I'm trying to get a count of how many PDFs were created last month. I'm using the following command but it's returning 0

我正在尝试计算上个月创建了多少个 PDF。我正在使用以下命令,但它正在返回0

find . -name '*.pdf' -mtime +46 ! -mtime +30 | wc -l

I'm in the correct directory and it seems like the logic is correct... any ideas on why this isn't working? Is there an easier way, say to pass the specific month I'm looking for instead of trying to calculate days like this?

我在正确的目录中,似乎逻辑是正确的......关于为什么这不起作用的任何想法?有没有更简单的方法,比如说通过我正在寻找的特定月份而不是尝试像这样计算天数?

采纳答案by kev

You are finding all pdffiles:

您正在查找所有pdf文件:

  • 46days ago
  • not 30days ago

    x>46 && x<=30  --> false
    
  • 46几天前
  • 不是30几天前

    x>46 && x<=30  --> false
    

It will return empty result.

它将返回空结果。



   Numeric arguments can be specified as
   +n     for greater than n,
   -n     for less than n,
   n      for exactly n.

If you want find all pdffiles (30<x<46):

如果要查找所有pdf文件 ( 30<x<46):

$ find . -name '*.pdf' -mtime +30 -mtime -46

回答by ghoti

You appear to be looking for files that are older than 46 days but not older (i.e. younger) than 30 days.

您似乎正在寻找早于 46 天但不早于(即小于)30 天的文件。

What about this?

那这个呢?

 find . -name '*.pdf' -mtime -46 -mtime +30

回答by Adam Liss

If you're using GNU findyou can specify the absolute dates like this:

如果您使用的是 GNU find,则可以像这样指定绝对日期:

find . -name '*.pdf' -newermt 2012-01-31 ! -newermt 2012-02-29 | wc -l

The -newermtoption will find files that have been modified more recently than an absolute time.

-newermt选项将查找比绝对时间更近修改的文件。

If you're not using GNU, you can use touchto create two files with the appropriate timestamps and find your PDFs like this:

如果您不使用 GNU,您可以使用touch创建两个具有适当时间戳的文件,并像这样找到您的 PDF:

touch -t 201201312359 oldest # 11:59 PM 1/31/2012
touch -t 201203010000 newest # midnight 3/1/2012
find . -name '*.pdf' -newer oldest ! -newer newest | wc -l

See the GNU documentationfor details.

有关详细信息,请参阅GNU 文档