linux:搜索最近修改过的 *.php 类型的文件

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

linux: search for files of type *.php recently modified

linuxfind

提问by Stoob

How do I adapt this to return recursively files of only extension *.php? thx!

我如何调整它以返回仅扩展名为 *.php 的递归文件?谢谢!

find . -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort

采纳答案by Adam Zalcman

Add -name '*.php':

添加-name '*.php'

find . -type f  -name '*.php' -printf '%TY-%Tm-%Td %TT %p\n' | sort

Note that since the expression is evaluated by findfrom left to right you must specify the -nametest before the -printfaction.

请注意,由于表达式是find从左到右计算的,因此您必须-name-printf操作之前指定测试。

See this manpagefor details about tests, actions and how find evaluates your expression.

有关测试、操作以及 find 如何评估您的表达式的详细信息,请参阅此联机帮助页

回答by Holger Just

find . -type f -name '*.php' -printf '%TY-%Tm-%Td %TT %p\n' | sort

You can find more options in the manfile of find.

你可以在manfile 中find找到更多选项。

回答by Efstathios Oikonomou

You could also use

你也可以使用

find . -type f -mtime -n -name '*.php' | sort    

where n is the number of days a file exists. For example

其中 n 是文件存在的天数。例如

find . -type f -mtime -1 -name '*.php' | sort 

should return all files that are less than a day old. That is useful if you want to filter you results.

应该返回所有不到一天的文件。如果您想过滤结果,这很有用。

回答by avivamg

Explanation: Use unix command find with -typeflag and regex for .phpend of file and -ctimefor creation time

说明:使用带有-type标志和正则表达式的unix 命令查找.php文件结尾和-ctime创建时间

The find utility recursively descends the directory tree for each path listed, evaluating an expression (composed of the 'primaries' and 'operands') in terms of each file in the tree.

find 实用程序针对列出的每个路径递归地降低目录树,根据树中的每个文件计算表达式(由“主要”和“操作数”组成)。

Solution:find . -name "*\.php" -type f -mtime -4w- which means in my current directory find all the php combination names in type file that were created in the last 4 weeks.

解决方案:find . -name "*\.php" -type f -mtime -4w- 这意味着在我的当前目录中找到过去 4 周内创建的类型文件中的所有 php 组合名称。

Extra Reading: According to documentation

额外阅读:根据文档

 -type t
         True if the file is of the specified type.  Possible file types are as fol-
         lows:

         b       block special
         c       character special
         d       directory
         f       regular file
         l       symbolic link
         p       FIFO
         s       socket

 -mtime n[smhdw]
         If no units are specified, this primary evaluates to true if the difference
         between the file last modification time and the time find was started,
         rounded up to the next full 24-hour period, is n 24-hour periods.

         If units are specified, this primary evaluates to true if the difference
         between the file last modification time and the time find was started is
         exactly n units.  Please refer to the -atime primary description for informa-
         tion on supported time units.