Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Do you mean the sum of all sizes? – cYrus Sep 20 '10 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 '10 at 12:04
Yes, I mean total file size of these files. – atricapilla Sep 20 '10 at 12:44
up vote 2 down vote accepted

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}'
share|improve this answer
Maybe you should use ls -lA --time-style=+%Y to ensure that the year is shown, and to hide . and ... – cYrus Sep 20 '10 at 13:11
@cYrus: Except that, since Tru64 is not a GNU system, it doesn't have --time-style. – Dennis Williamson Sep 20 '10 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 '10 at 17:04
@cYrus: You are correct concerning the -A. I have edited my answer. – Dennis Williamson Sep 20 '10 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. – Gilles Sep 20 '10 at 18:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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