0

I work with AIX and I need to find out the total sum of files created in the last 30 days within a directory. I already managed to extract to a file everything created in those 30 days, and with the command AWK I managed to create another file in which I have the weight of each one of those files. In conclusion, I already have a file with the weight of each line, but I need to add each to get the total weight and I do not know how to do it. It is important to clarify that there are about 2,000,000 lines. Thank you

  • Please give an example with ls -l with 3 files and what you expect the output to be. – hschou Jun 26 '17 at 20:57
  • What do you mean by weight? The size? The disk usage? – Stéphane Chazelas Jun 26 '17 at 21:55
  • Do you really mean created or last modified? – Stéphane Chazelas Jun 26 '17 at 21:56
1

To get a sum of the sizes of the files listed one per line in file.list (so assumes file names don't contain newline characters):

perl -lne '$sum+=-s; END{print $sum}' file.list

Note that for symlinks, that counts the size of the target of the symlink.

That's the apparent size, which is typically different from the disk usage.

0

This command will show the sum of file sizes which is changed the last 30 days:

find . -mtime -30 -exec stat -c %s {} \; | awk '{SUM+=$1}END{print SUM}'

Edit: sum of files

  • Thanks, but I already know the amount of lines. There are like 2.000.000. What I need is the sum of the size oh each one. – fedeemp Jun 26 '17 at 20:35
0

I use this command and it works:

awk '{suma=0; for (i=1; i<=NF; i++) suma=$i;sumatotal=sumatotal+suma; print sumatotal}' COT2

COT2 is the name of the file. I get the total size in KB, and then I convert this number to GB.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.