shell脚本过滤du并通过子文件夹中文件内的字符串查找
我在 cygwin 上运行以下命令:
查找 /cygdrive/d/tmp/* -max深度 0 -mtime -150 -类型 d | xargs du --max-深度 = 0 >文件夹大小报告.csv
我打算使用此命令执行以下操作:
对于在过去 150 天内修改的 /d/tmp/
下的每个文件夹,检查其总大小(包括其中的文件)并将其报告给文件文件夹大小报告.csv
然而现在这对我来说还不够好,因为事实证明每个
<代码>/d/tmp/subfolder1/somefile.properties /d/tmp/subfolder2/somefile.properties /d/tmp/subfolder3/somefile.properties /d/tmp/subfolder4/somefile.properties
正如您在每个子文件夹X中看到的那样,有一个名为 somefile.properties
的文件 它里面有一个属性 SOMEPROPKEY=3808612800100
(以及其他属性)
这是以毫秒为单位的时间,我需要更改命令,以便代替 -mtime -150
它仅包含在整个计算中 subfolderX 内有一个文件 somefile.properties
,其中 SOMEPROPKEY=3808612800100
是未来的时间(以毫秒为单位),如果值 SOMEPROPKEY=23948948
已过去,则根本不包含该文件夹 在 foldersizesreport.csv
中,因为它与我无关。
所以结果报告应该是这样的:
/d/tmp/,subfolder1,<其大小(以 KB 为单位)> /d/tmp/,子文件夹2,<其大小(以 KB 为单位)>
如果 subfolder3
有一个 SOMEPROPKEY=34243234
(过去的时间以毫秒为单位),那么它就不会出现在该 csv 文件中。
所以基本上我正在寻找:
查找 /cygdrive/d/tmp/* -max深度 0 -mtime -150 -type d | <仅包含文件属性的子文件夹 SOMEPROPKEY=28374874827 - 未来的时间(以毫秒为单位) 不是过去| xargs du --max-深度 = 0 >文件夹大小报告.csv
I have the following command that I run on cygwin:
find /cygdrive/d/tmp/* -maxdepth 0
-mtime -150 -type d |
xargs du --max-depth=0 > foldersizesreport.csv
I intended to do the following with this command:
for each folder under /d/tmp/
that was modified in last 150 days, check its total size including files within it and report it to file foldersizesreport.csv
however that is now not good enough for me, as it turns out inside each
/d/tmp/subfolder1/somefile.properties /d/tmp/subfolder2/somefile.properties /d/tmp/subfolder3/somefile.properties /d/tmp/subfolder4/somefile.properties
so as you see inside each subfolderX there is a file named somefile.properties
inside it there is a property SOMEPROPKEY=3808612800100
(among other properties)
this is the time in millisecond, i need to change the command so that instead of -mtime -150
it will include in the whole calculation only
subfolderX that has a file inside them somefile.properties
where the SOMEPROPKEY=3808612800100
is the time in millisecond in future, if the value SOMEPROPKEY=23948948
is in past then dont at all include the folder
in the foldersizesreport.csv
because its not relevant to me.
so the result report should be looking like:
/d/tmp/,subfolder1,<itssizein KB> /d/tmp/,subfolder2,<itssizein KB>
and if subfolder3
had a SOMEPROPKEY=34243234
(time in ms in past) then it would not be in that csv file.
so basically I'm looking for:
find /cygdrive/d/tmp/* -maxdepth 0 -mtime -150 -type d | <only subfolders that have in them property in file SOMEPROPKEY=28374874827 - time in ms in future and not in past | xargs du --max-depth=0 > foldersizesreport.csv
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是整个事情的 Perl 版本:
filter.pl
使用
输出(带有您的示例)
Here's a perl version for the whole thing:
filter.pl
usage
output (with your sample)