I would like to extract files from

ls -la

based on certain creation year (e.g. 1999), and then calcute the file size of these files. How to accomplish that?

  • Do you mean the sum of all sizes?
    – cYrus
    Sep 20, 2010 at 12:04
  • The size of the files is given by ls. Do you mean, you want to sum the total size of these files?
    – kmarsh
    Sep 20, 2010 at 12:04
  • Yes, I mean total file size of these files. Sep 20, 2010 at 12:44

1 Answer 1


Since I don't think the version of find in Tru64 supports the same options that GNU find does and there doesn't seem to be a stat, you'll probably have to parse ls which is generally discouraged.

This should work, but you'll need to adjust the field numbers to match the way your ls output is laid out.

ls -lA | awk '$8==1999 {total += $5} END{print "Total: " total}'
  • Maybe you should use ls -lA --time-style=+%Y to ensure that the year is shown, and to hide . and ...
    – cYrus
    Sep 20, 2010 at 13:11
  • @cYrus: Except that, since Tru64 is not a GNU system, it doesn't have --time-style. Sep 20, 2010 at 13:19
  • Ok for that, but using the -a option instead of -A you'll count the size of the directories . and .. too. Unless Tru64 doesn't behave differently...
    – cYrus
    Sep 20, 2010 at 17:04
  • @cYrus: You are correct concerning the -A. I have edited my answer. Sep 20, 2010 at 18:33
  • I would write LC_ALL=C ls -lA, to avoid date formats that don't show the year in the same position. @atricapilla: note that if there are any subdirectories, this will count the size of the directory entry (not the size or number of the files in the subdirectory); add /^-/ && at the beginning of the awk script to only count regular files. Sep 20, 2010 at 18:57

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.