My shell engine is either Busybox 1.31.0 or bash 3.2
I need to get the size of the files retrieved from find command.
I've been trying to find only files, which have been modified more than 60 days ago and at the same time get the size of all those files SUMARIZED preferably in a one-liner in MB notation. Here's what I've tried.
find -type f -mtime +60 -print0 | xargs -0 du -smc
and
find -type f -mtime +60 -exec du -smc {} \;
The former retrieves line-by-line all files older than 60 days (no problem at all until here) but it weirdly calculates the size several times between all those lines and at the final line I get a "total" size that does not correspond to the actual total size of the output. Here's what it looks like.
.....
.....
0 ./FOLDER 2018/Copy #183 of ~$DATABASE OTHERS - NOV.18N.xlsx
42 ./FOLDER 2018/F9C8A618.tmp
0 ./FOLDER 2018/Copy #166 of ~$DATABASE PORTFOLIO NOV.18.xlsx
3275 total
10 ./FOLDER 2018/CFDC6981.tmp
2 ./FOLDER 2018/D5AAF4EB.tmp
0 ./LIFE INSURANCE/Copy #15 of ~$Copy of LIFE INSURANCE CLIENTS.xlsx
12 total
The latter's output calculate the size of every coinciding file line-by-line with no total.
What I'm expecting is:
0 ./FOLDER 2018/Copy #183 of ~$DATABASE OTHERS - NOV.18N.xlsx
42 ./FOLDER 2018/F9C8A618.tmp
0 ./FOLDER 2018/Copy #166 of ~$DATABASE PORTFOLIO NOV.18.xlsx
10 ./FOLDER 2018/CFDC6981.tmp
2 ./FOLDER 2018/D5AAF4EB.tmp
0 ./LIFE INSURANCE/Copy #15 of ~$Copy of LIFE INSURANCE CLIENTS.xlsx
54 total
Or simply just the real size result without all the lines
54 total
Any help would be well received.
find
, or the size of the files returned byfind
? Your commands are doing the second, but your question asks for the first. Also, whatfind
is this? Do you have GNU tools? You mention busybox, so I guess this isn't a full GNU/Linux system?-printf %b
and get rid ofdu
entirely:find . -mtime +60 -type f -printf '%b\n' | awk '{s+=$1}END{print s/2048"M"}'
. With busybox find and du, you should usedu -smc $(find ...)
and hope for the best ;-) Whether your shell is bash or busybox matters very little.find . -type f -mtime +60 -printf '%D:%i %b\n' | awk '!a[$1]++{s+=$2}END{print s/2048"M"}'
. Just likedu
, this is not smart enough to do anything sensible about file referenced via hard links from somewhere else.