How can I find the size of files added to a folder after a particular date

Hi,
I want to find the size of the files added to a folder after a certain date(say 1st of october), I know we can list the files which were created after a certain date , but is there anyway to find the total size of those files ?

Not exactly. Inodes have three dates, and of course both files and directories are inodes. Seem man stat:

           time_t   st_atime;     /* Time of last access */
           time_t   st_mtime;     /* Last modification time */
           time_t   st_ctime;     /* Last file status change time */
                                  /* Measured in secs since */
                                  /* 00:00:00 GMT, Jan 1, 1970 */

However, all a directory holds is pairs of entry name strings and binary inode numbers. This is why hard links must be on the same device. In some respects, it is sadly plain, but simple.

If the file was modified or status'd at the time it was linked into the directory, you can use those times. The directory times are for the last file added or removed, which includes renames (mv), as that is done by adding a hard link (another directory entry for the same inode) and then deleting the original directory entry (ln a b;rm a).

Maybe you're looking for something like this.

The output of ls -l are different in some versions but you can give this a try:

ls -l | awk '!/^d/ && /2010-10-01/{s+=$5}END{print s}'

If you want to segregate files by the file times as shown in man stat, you can use 'find'. There are two flavors there.

  • The mtime/time/atime arguments are real time clock sensitive and day-granular, but fine for gross bracketing. You can say
    text -ctime +3 -ctime -5
    to get 2 days 3-d days ago to the second.
  • The newer works with the modification time and a marker file per -newer, so you can say
    text -newer a ! -newer b
    to get files in any exact range in seconds. See man touch for creating and resetting the mtimes of files.

I was at a loss for better tools to access stat() data, so I wrote one, but the latest version, with arguments for every stat element, seems to be hiding. It can take in a stream of file names and spits them out annotated with the UNIX mtime, in integer seconds since 1970 started, GMT:

$ cat mysrc/mystat.c

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>

static void psf( char * buf )
{
        struct stat s ;

        if ( 0 > stat( buf, &s ) )
        {
                perror( buf );
                return ; ;
        }

        if ( 0 > printf( "%u\t%s\n", s.st_mtime, buf ) )
        {
                if ( !ferror( stdout ) )
                        exit( 0 );
                perror( "stdout" );
                exit( 1 );
        }
}

int main( int argc, char **argv )
{
        char buf[PATH_MAX + 2];
        char *cp ;
        int i ;
        int clf = 0 ;

        for ( i = 1 ; i < argc ; i++ )
        {
                clf ++ ;
                psf( argv );
        }

        if ( !clf ) while ( fgets( buf, sizeof buf, stdin ) )
        {
                if ( !( cp = strchr( buf, '\n' ) ) )
                {
                        fprintf( stderr, "File path too long: '%s'\n", buf );
                        continue ;
                }

                *cp = NULL ;
                psf( buf );
        }

        if ( !ferror( stdin ) )
                exit( 0 );

        perror( "stdin" );
        exit( 1 );
}