Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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

Actually there are tow questions.

First I have to search the files using FIND command that will show only the files for December 2012

And Secondly I need to see the Total size of files searched

I used this command

find /storage/backup/rman/ -mtime +90 -mtime -120 -exec ls -lrth {} \;

But it also gave me the Files of November which I dont want

-rw-r--r-- 1 oraprod dba 8.7K Dec  1 22:40 /storage/backup/rman/full_011212.log
-rw-r----- 1 oraprod dba 3.3G Dec 11 22:34 /storage/backup/rman/BKPPROD_aknskgvb.F_bkp
-rw-r----- 1 oraprod dba 34M Dec  1 22:40 /storage/backup/rman/ctrl_011223
-rw-r----- 1 oraprod dba 1.3M Dec  1 22:33 /storage/backup/rman/BKPPROD_8lnrq765.F_bkp
-rw-r--r-- 1 oraprod dba 8.0K Dec 20 22:45 /storage/backup/rman/full_201212.log
-rw-r----- 1 oraprod dba 34M Dec  2 22:42 /storage/backup/rman/ctrl_021223
-rw-r----- 1 oraprod dba 2.5G Dec 11 22:38 /storage/backup/rman/BKPPROD_ajnskgvb.F_bkp
-rw-r----- 1 oraprod dba 34M Dec 13 22:46 /storage/backup/rman/ctrl_131223
-rw-r--r-- 1 oraprod dba 8.0K Dec 17 22:44 /storage/backup/rman/full_171212.log
-rw-r--r-- 1 oraprod dba 8.0K Dec 10 22:38 /storage/backup/rman/full_101212.log
-rw-r--r-- 1 oraprod dba 8.0K Dec 13 22:46 /storage/backup/rman/full_131212.log
-rw-r--r-- 1 oraprod dba 1.4K Nov 30 22:00 /storage/backup/rman/full_301112.log
-rw-r----- 1 oraprod dba 34M Dec  8 22:46 /storage/backup/rman/ctrl_081223
-rw-r--r-- 1 oraprod dba 9.2K Dec 12 22:43 /storage/backup/rman/full_121212.log

when i pass the du -ch at the end of command this is the result

8.0K    ./.gnome/gnome-vfs
12K     ./.gnome
24K     ./lsat-
920K    ./lsat-
8.0K    ./.gconf/desktop/gnome/accessibility/keyboard
12K     ./.gconf/desktop/gnome/accessibility
8.0K    ./.gconf/desktop/gnome/peripherals/keyboard/host-mdfr-prod/0
12K     ./.gconf/desktop/gnome/peripherals/keyboard/host-mdfr-prod
16K     ./.gconf/desktop/gnome/peripherals/keyboard
20K     ./.gconf/desktop/gnome/peripherals
36K     ./.gconf/desktop/gnome
40K     ./.gconf/desktop
8.0K    ./.gconf/apps/panel/applets/clock/prefs
12K     ./.gconf/apps/panel/applets/clock
8.0K    ./.gconf/apps/panel/applets/workspace_switcher/prefs
12K     ./.gconf/apps/panel/applets/workspace_switcher
8.0K    ./.gconf/apps/panel/applets/window_list/prefs
12K     ./.gconf/apps/panel/applets/window_list
40K     ./.gconf/apps/panel/applets
44K     ./.gconf/apps/panel
8.0K    ./.gconf/apps/puplet
56K     ./.gconf/apps
100K    ./.gconf
8.0K    ./.nautilus/metafiles
12K     ./.nautilus
4.0K    ./.eggcups
196K    ./.gstreamer-0.10
4.0K    ./.redhat/esc
8.0K    ./.redhat
8.0K    ./.gnome2/share/cursor-fonts
8.0K    ./.gnome2/share/fonts
20K     ./.gnome2/share
4.0K    ./.gnome2/keyrings
4.0K    ./.gnome2/accels
4.0K    ./.gnome2/nautilus-scripts
36K     ./.gnome2
12K     ./.metacity/sessions
16K     ./.metacity
4.0K    ./.Trash
4.0K    ./.gnome2_private
68K     ./.gconfd
4.0K    ./.mozilla/extensions
4.0K    ./.mozilla/plugins
12K     ./.mozilla
4.0K    ./Desktop
2.5M    .
2.5M    total
share|improve this question
Not very elegant but: find -type f -mtime +90 -mtime -120 -exec du -c {} + | grep -E '^[0-9]+\stotal$' would print one or more totals which you can add together to the grand total. – frostschutz Mar 24 '13 at 15:09
up vote 2 down vote accepted

Some versions of find (non-embedded Linux, Cygwin, OSX, FreeBSD) allow you to compare a file's modification time with a reference date with the -newermt operator.

find /storage/backup/rman -newermt '2012-12-01' ! -newermt '2013-01-01'

You can't use -mtime to tell whether a file was modified at a particular date, because this operator is relative to the time you run the find command. If your find doesn't have the -newermt operator, create reference files and use the -newer operator.

touch -t 201212010000 start
touch -t 201301010000 end
find /storage/backup/rman -newer start ! -newer end

To get the total size of the files, use du -c and keep only the last (“total”) line. You'll need to exclude directories, because when you pass a directory to du, it adds up the sizes of all the files under that directory.

find /storage/backup/rman -type f -newermt '2012-12-01' ! -newermt '2013-01-01' -exec du -c {} + | tail -n 1

If you have a large number of files, the length of the command line might be too large, so find will run du multiple times and the command above would only list the output from the last batch. In that case you'll need to add up the amounts from each run. Here's one way to do this.

find /storage/backup/rman -type f -newermt '2012-12-01' ! -newermt '2013-01-01' \
     -exec sh -c 'du "$@" | tail -n 1' _ {} + |
awk '{total += $1} END {print total}'

Exercise: what's wrong with the following command? (I.e. in what unusual but possible situation will it report a wrong figure?)

find /storage/backup/rman -type f -newermt '2012-12-01' ! -newermt '2013-01-01' \
     -exec du {} + |
awk '$2 == "total" {total += $1} END {print total}'
share|improve this answer

From http://stackoverflow.com/questions/64649/how-do-i-get-the-unix-find-command-to-print-out-the-file-size-with-the-file-name

find . -name '*.ear' -exec ls -lh {} \;

just the h extra from jer.drab.org's reply. saves time converting to MB mentally.

Related Resources

share|improve this answer

First retrieve the file size in bytes, then sum them up:

sed 's/\s\+/+/g' <<<$(find /storage/backup/rman/ -mtime +90 -mtime -120 -exec stat -c "%s" {} \;) | bc


To see the files as well,

du -chs $(find /storage/backup/rman/ -mtime +90 -mtime -120)

share|improve this answer
warl0ck, it it possible to also see the files because it only shows the size in bytes and later I calculated the size which is 51GB. – OmiPenguin Mar 24 '13 at 7:23
@UmairMustafa provided an alternative way – warl0ck Mar 24 '13 at 7:57
Still it is going Nov Files...... Otherwise it is great – OmiPenguin Mar 24 '13 at 8:23
@UmairMustafa I don't get what you mean – warl0ck Mar 24 '13 at 8:30
Actually what i mean is I only want the files of Dec and not Nov. When we pass the -mtime +90 -mtime -120 for some reason it also returns the Nov Files along Dec files. – OmiPenguin Mar 24 '13 at 10:00

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.