Linux 查找过去 24 小时内更改过的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16085958/
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 22:44:56  来源:igfitidea点击:

Find the files that have been changed in last 24 hours

linuxbashfind

提问by HymanWM

E.g., a MySQL server is running on my Ubuntu machine. Some data has been changed during the last 24 hours.

例如,一个 MySQL 服务器正在我的 Ubuntu 机器上运行。某些数据在过去 24 小时内已更改。

What (Linux) scripts can find the files that have been changed during the last 24 hours?

什么 (Linux) 脚本可以找到过去 24 小时内已更改的文件?

Please list the file names, file sizes, and modified time.

请列出文件名、文件大小和修改时间。

采纳答案by Xavjer

To find all files modified in the last 24 hours (last full day) in a particular specific directory and its sub-directories:

要在特定的特定目录及其子目录中查找过去 24 小时(最后一整天)内修改的所有文件:

find /directory_path -mtime -1 -ls

Should be to your liking

应该是你喜欢的

The -before 1is important - it means anything changed one day or less ago. A +before 1would instead mean anything changed at least one day ago, while having nothing before the 1would have meant it was changed exacted one day ago, no more, no less.

-之前1是非常重要的-这意味着任何改变一天或更短前。A +before1表示至少在一天前发生了任何变化,而在 the 之前没有任何变化1则意味着它在一天前发生了变化,不多也不少。

回答by Michael

You can do that with

你可以这样做

find . -mtime 0

From man find:

来自man find

[The] time since each file was last modified is divided by 24 hours and any remainder is discarded. That means that to match -mtime 0, a file will have to have a modification in the past which is less than 24 hours ago.

[The] 自上次修改每个文件以来的时间除以 24 小时,其余部分将被丢弃。这意味着要匹配 -mtime 0,文件必须在过去不到 24 小时之前进行过修改。

回答by BhandariS

This command worked for me

这个命令对我有用

find . -mtime -1 -print

回答by Stephen G Tuggy

On GNU-compatible systems (i.e. Linux):

在 GNU 兼容系统(即 Linux)上:

find . -mtime 0 -printf '%T+\t%s\t%p\n' 2>/dev/null | sort -r | more

This will list files and directories that have been modified in the last 24 hours (-mtime 0). It will list them with the last modified time in a format that is both sortable and human-readable (%T+), followed by the file size (%s), followed by the full filename (%p), each separated by tabs (\t).

这将列出过去 24 小时内修改过的文件和目录 ( -mtime 0)。它将以可排序和人类可读的格式 ( %T+)列出它们的最后修改时间,然后是文件大小 ( %s),然后是完整的文件名 ( %p),每个文件名都由制表符 ( \t)分隔。

2>/dev/nullthrows away any stderr output, so that error messages don't muddy the waters; sort -rsorts the results by most recently modified first; and | morelists one page of results at a time.

2>/dev/null丢弃任何 stderr 输出,以便错误消息不会混淆;sort -r首先按最近修改的结果对结果进行排序;并一次| more列出一页结果。

回答by resedasue

For others who land here in the future (including myself), add a -name option to find specific file types, for instance: find /var -name "*.php" -mtime -1 -ls

对于将来登陆这里的其他人(包括我自己),添加一个 -name 选项来查找特定的文件类型,例如: find /var -name "*.php" -mtime -1 -ls

回答by Maxim Egorushkin

Another, more humane way:

另一种更人性化的方式:

find /<directory> -newermt "-24 hours" -ls

or:

或者:

find /<directory> -newermt "1 day ago" -ls

or:

或者:

find /<directory> -newermt "yesterday" -ls