修改特定月上市文件:UNIX / BASH [英] UNIX / BASH: Listing files modified in specific month

查看:106
本文介绍了修改特定月上市文件:UNIX / BASH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与上市具体修改每月文件(例如,Februrary)挣扎。
这里有几次不成功的尝试:

I am struggling with listing files modified in specific month (for example, Februrary). Here are several unsuccessful attempts:

1)我试图创建临时文件,并在接下来的一个月的时间戳记设置为在第一时间与目标月首次在查找中使用-newer,像这样的:

1) I tried creating temporary files and setting their timestamp to the first time in the next month and the first time in the target month and use -newer in find, like this:

find -newer "$from" ! -newer "$to"

这列出的时间间隔修改的文件($而来,$至],但我想的时间间隔[$从,$到)(否则,就不会有上的第一秒创建的文件误报下个月)。清单月修改过的文件是多余的问题,因为这需要设置时间戳来最伟大的人们仍然在二月之一,但2月的天数取决于它是否是闰年,这需要额外的检查

This lists files modified in the time interval ($from, $to], but I would like the time interval [$from, $to) (otherwise, there would be false positives on files created on the first second in the next month). Listing files modified in February is extra problem, since this would require to set one of the timestamps to the greatest one still in February, but the number of days in February varies depending on whether it is a leap year or not, which requires extra checking.

2)如果我使用 LS 我看到很多并发症解析,因为可能时,该用户名或组包含空格。

2) If I use ls I see a lot of complication when parsing, because of the possibility that user name or group contain whitespace.

是否有这样做的(所以它适用于任何一个月,无论文件名等)?

Is there an easy way and relatively portable way for doing this (so it works for any month, regardless of file names, etc.)?

推荐答案

日期允许您轻松地生成目的一样,时间戳:

date allows you to easily generate timestamps for purposes like that:

date -d "01-Mar-2011 -1 sec" # last second of Feb-2011

幸运的是,相同的语法是可能的找到

month="Mar-2010"
find . -newermt "01-$month -1 sec" -and -not -newermt "01-$month +1 month -1 sec"

会发现,在2010年3月修改的所有文件

will find all files modified in March 2010

这篇关于修改特定月上市文件:UNIX / BASH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆