Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Shell script help

Name: Anonymous 2010-11-03 22:18

How can I change my code to be able to compare the size of two files.

if [ -f $1 ] && [ -f $2 ] && [ ! $1 -ef $2 ]; then
    size1=$(du $1)
    size2=$(du $2)
    if [ $1 -gt $2 ]; then
     echo "$1 is bigger"
    else
      echo "$1 is smaller"
    fi
fi

Name: Anonymous 2010-11-04 19:03

>>16
/* Get the size of a file. */

#include <stdio.h>

int main(int argc, char *argv[])
{
    FILE *file;
    long size;

    if (argc < 2)
        fprintf(stderr, "Please provide a filename argument.\n");
    else if ((file = fopen(argv[1], "rb")) == NULL)
        fprintf(stderr, "Error opening file.\n");
    else if (fseek(file, 0, SEEK_END))
        fprintf(stderr, "Error seeking to end of file.\n");
    else if ((size = ftell(file)) == -1)
        fprintf(stderr, "Error obtaining file position.\n");
    else
        printf("%ld\n", size);

    return 0;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List