#include <stdio.h>
#include <stdlib.h>


int check_permissions(char *filter, char *permission){
    for(int i = 0; i<9;i++){
        if (filter[i] != '-'){
            if(filter[i] != permission[i]){
                return 1;
            }
        }
    }
    return 0;
}

int main(int argc, char** argv) {
    if (!(argc == 2 || argc == 3)) {
        fprintf(stderr, "USAGE: count_large size [permissions]\n");
        return 1;
    }
    char line[101];
    char permission[9];
    int size;
    int num = 0;
    int min = strtol(argv[1], NULL, 10);
    fgets(line, 101, stdin);
    while(fscanf(stdin, "%s %*d %*s %*s %d %*[^\n]", permission, &size) == 2){
        if((size > min) && (permission[0] != 'd')){
            if(argc == 3){
                if(check_permissions(argv[2], permission + 1) == 0){
                    num ++;
                }
            }else{
                num ++;
            }
        }
    };

    printf("%d\n", num);

    return 0;
}

given the output of ls -l:

    total 329
    -rwx------  1 reid  staff    1734 Jun 22 14:52 prog
    -rw-------  1 reid  staff   21510 Apr  6 12:10 tmp.txt
    -rwxr-xr-x  1 reid  staff    8968 Feb  1 2013 xyz
    -rw-r--r--  1 reid  staff      88 Feb 15 2013 xyz.c
Running

$ count_large 1000 rwx------

will print 2 (followed by a single newline \n character) because prog and xyz are both larger than 1000 bytes and have at least the permissions specified.

Running

$ count_large 1000

will print 3 (followed by a single newline \n character) because there are three files larger than 1000 bytes.
