Linux命令检查文件系统中的新文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5893748/
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
Linux command to check new files in file system
提问by Gabriel Spiteri
We have linux machine we would like to check what new files have been added between a certain date range.
我们有一台 linux 机器,我们想检查在某个日期范围内添加了哪些新文件。
I only have SSH access to this box and it's openSUSE 11.1
我只能通过 SSH 访问这个盒子,它是 openSUSE 11.1
Is there some sort of command that can give me a list of files that have been added to the filesystem between say 04/05/2011 and 05/05/2011
是否有某种命令可以为我提供在 04/05/2011 和 05/05/2011 之间添加到文件系统的文件列表
Thanks
谢谢
Regards Gabriel
问候加布里埃尔
采纳答案by ilalex
There are bunch of ways for doing that.
有很多方法可以做到这一点。
First one:
第一:
start_date=201105040000
start_date=201105040000
end_date=201105042359
end_date=201105042359
touch -t ${start_date} start
touch -t ${start_date} start
touch -t ${end_date} end
touch -t ${end_date} end
find /you/path -type f -name '*you*pattern*' -newer start ! -newer end -exec ls -s {} \;
find /you/path -type f -name '*you*pattern*' -newer start ! -newer end -exec ls -s {} \;
Second one:find files modified between 20 and 21 days ago:
第二个:查找20到21天前修改过的文件:
find -ctime +20 -ctime -21
find -ctime +20 -ctime -21
finds files modified between 2500 and 2800 minutes ago:
查找在 2500 到 2800 分钟前修改过的文件:
find -cmin +2500 -cmin -2800
find -cmin +2500 -cmin -2800
And read this topictoo.
并阅读此主题。
回答by jedwards
I misunderstood your question. Depending on what filesystem you are using, it may or may not store creation time.
我误解了你的问题。根据您使用的文件系统,它可能会或可能不会存储创建时间。
My understanding is that ext2/3/4 do not store creation time, but modified, changed (status, which is slightly different), and access times are.
我的理解是 ext2/3/4 不存储创建时间,而是修改、更改(状态,略有不同)和访问时间。
Fat32 on the other hand does contain creation timestamps IIRC.
另一方面,Fat32 确实包含创建时间戳 IIRC。
If you are using an ext filesystem, you have two options it seems:
如果您使用的是 ext 文件系统,您似乎有两个选择:
1.Settle for finding all of the files that were modified between two dates (which will include created files, but also files that were just edited). You could do this using find.
1.Settle 查找在两个日期之间修改过的所有文件(包括创建的文件,也包括刚刚编辑的文件)。你可以使用find来做到这一点。
2.Create a script/cronjob that will document the contents of your filesystem at some interval, e.g.
2.创建一个脚本/cronjob,它将在某个时间间隔记录文件系统的内容,例如
find / > filesystem.$(date +%s).log
and then run diffs to see what has been added. This, of course, would prevent you from looking backwards to time before you started making these logs.
然后运行差异以查看已添加的内容。当然,这会阻止您在开始制作这些日志之前回顾时间。
回答by Ryan C. Thompson
Well, you could use find
to get a list of all the files that were last-modifiedin a certain time window, but that isn't quite what you want. I don't think you can tell just from a file's metadata when it came into existence.
好吧,您可以使用find
获取在特定时间窗口内最后修改的所有文件的列表,但这并不是您想要的。我认为您不能仅从文件的元数据中看出它何时存在。
Edit: To list the files along with their modification dates, you can pipe the output of find
through xargs
to run ls -l
on all the files, which will show the modification time.
编辑:要列出文件及其修改日期,您可以find
通过管道输出对所有文件xargs
运行ls -l
,这将显示修改时间。
find /somepath -type f ... -print0 | xargs -0 -- ls -l
回答by ilalex
You can try one of these:
您可以尝试以下方法之一:
find -newerct "1 Aug 2013" ! -newerct "1 Sep 2013" -ls
find . -mtime $(date +%s -d"Jan 1, 2013 23:59:59") -mtime $(date +%s -d"Jan 2, 2016 23:59:59")
find /media/WD/backup/osool/olddata/ -newermt 20120101T1200 -not -newermt 20130101T1400
find . -mtime +1 -mtime -3
find . -mtime +1 -mtime -3 > files_from_yesterday.txt 2>&1
find . -mtime +1 -mtime -3 -ls > files_from_yesterday.txt 2>&1
touch -t 200506011200 first
touch -t 200507121200 last
find / -newer first ! -newer last
#!/bin/bash
for i in `find Your_Mail_Dir/ -newermt "2011-01-01" ! -newermt "2011-12-31"`; do
mv $i /moved_emails_dir/
Hope this helps.
希望这可以帮助。