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
get number of files modified last month
提问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 pdf
files:
您正在查找所有pdf
文件:
46
days agonot
30
days agox>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 pdf
files (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 find
you can specify the absolute dates like this:
如果您使用的是 GNU find
,则可以像这样指定绝对日期:
find . -name '*.pdf' -newermt 2012-01-31 ! -newermt 2012-02-29 | wc -l
The -newermt
option will find files that have been modified more recently than an absolute time.
该-newermt
选项将查找比绝对时间更近修改的文件。
If you're not using GNU, you can use touch
to 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 文档。