我如何找到今天在 Unix/Linux 中创建的所有文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/801095/
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
How do I find all the files that were created today in Unix/Linux?
提问by
How do I find all the files that were create only today and not in 24 hour period in unix/linux
如何在 unix/linux 中找到仅在今天创建而不是在 24 小时内创建的所有文件
回答by Espo
回答by Alnitak
On my Fedora 10 system, with findutils-4.4.0-1.fc10.i386
:
在我的 Fedora 10 系统上,使用findutils-4.4.0-1.fc10.i386
:
find <path> -daystart -ctime 0 -print
The -daystart
flag tells it to calculate from the start of today instead of from 24 hours ago.
该-daystart
标志告诉它从今天开始计算,而不是从 24 小时前开始计算。
Note however that this will actually list files created ormodified in the last day. find
has no options that look at the true creation date of the file.
但是请注意,这实际上会列出在最后一天创建或修改的文件。 find
没有查看文件真实创建日期的选项。
回答by Pete Jordan
You can't. @Alnitak's answer is the best you can do, and willgive you all the new files in the time period it's checking for, but -ctime
actually checks the modification time of the file's inode (file descriptor), and so will also catch any older files (for example) renamed in the last day.
你不能。@Alnitak 的答案是你能做的最好的,它会在它检查的时间段内为你提供所有新文件,但-ctime
实际上会检查文件 inode(文件描述符)的修改时间,因此也会捕获任何旧文件(例如)在最后一天重命名。
回答by Ankit Khare
find . -mtime -1 -type f -print
回答by FtheBuilder
You can use find
and ls
to accomplish with this:
您可以使用find
和ls
来完成:
find . -type f -exec ls -l {} \; | egrep "Aug 26";
It will find all files in this directory, display useful informations (-l
) and filter the lines with some date you want... It may be a little bit slow, but still useful in some cases.
它将查找此目录中的所有文件,显示有用信息 ( -l
) 并使用您想要的日期过滤行......这可能有点慢,但在某些情况下仍然有用。
回答by Mavric
Just keep in mind there are 2 spaces between Aug and 26. Other wise your find command will not work.
请记住,8 月和 26 日之间有 2 个空格。否则您的 find 命令将不起作用。
find . -type f -exec ls -l {} \; | egrep "Aug 26";
回答by Samuurai
If you're did something like accidentally rsync'd to the wrong directory, the above suggestions work to find new files, but for me, the easiest was connecting with an SFTP client like Transmit then ordering by date and deleting.
如果您不小心将 rsync 同步到错误的目录,上述建议可以找到新文件,但对我来说,最简单的方法是连接 SFTP 客户端(如 Transmit),然后按日期排序并删除。
回答by Jim
I use this with some frequency:
我以某种频率使用它:
$ ls -altrh --time-style=+%D | grep $(date +%D)
回答by donaldgavis
Use ls or find to have all the files that were created today.
使用 ls 或 find 来获取今天创建的所有文件。
Using ls : ls -ltr | grep "$(date '+%b %e')"
使用 ls : ls -ltr | grep "$(date '+%b %e')"
Using find : cd $YOUR_DIRECTORY
; find . -ls 2>/dev/null| grep "$(date '+%b %e')"
使用find:cd $YOUR_DIRECTORY
;find . -ls 2>/dev/null| grep "$(date '+%b %e')"
回答by Barath Ravichander
After going through may posts i found the best one that really works
经过五月的帖子后,我找到了真正有效的最好的帖子
find $file_path -type f -name "*.txt" -mtime -1 -printf "%f\n"
This prints only the file name like
abc.txt
not the /path/tofolder/abc.txt
这仅打印文件名称,如
abc.txt
不/path/tofolder/abc.txt
Also also play around or customize with -mtime -1
也可以玩耍或自定义 -mtime -1