shell script filter du and find by a string inside a file in a subfolder
- by Jason
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