Steve Youngs wrote at 10/29/99 03:18 CET:
> 
> Okay, I'm trying to get a script to do one of the following:
> 
>         if [ sizeof(file1) < sizeof(file2)]; then
>                 cp file2 file3
>         fi
> 
> or
> 
>         if [ sizeof(file1) < 1024 ]; then
>                 cp file2 file3
>         fi
> 
<snip>

Suggestions received were:
"Baskette, John" wrote:
> 
> Something like this should work:
> 
>    sizeof () {
>       ls -l $1 | sed 's/  */ /g' | cut -f5 -d' '
>    }
> 
<snip>

(where the sed command should really read "tr -s ' '" :-)

Marc Mutz wrote:
> 
> #!/bin/bash
> 
> size1=$(ls -l file1|(read perms num_hd_links user group size rest; \
> echo $size) )
> size2=$(ls -l file2|(read perms num_hd_links user group size rest; \
> echo $size) )
> 
> if [ $size1 -gt $size2 ];then
>         # sizeof(file1) > sizeof(file2)
> else
>         # sizeof(file1) <= sizeof(file2)
> fi
> 
<snip>

[EMAIL PROTECTED] wrote:
>
> sizeof() { local lies; lies=$(ls -l $1 2>/dev/null); if test -f $1
>     then  (echo $lies|cut -d' ' -f 5);
>     else  echo NAN;
>    fi
>    }
> 
<snip>

All of these focused on providing something like a sizeof function,
which is of course the most useful version. But if you just wanted to
know what file in a given set was the biggest (the samllest), you'd use

biggest_in () {
        ls -S1 "$@" | head -n1
}

or

smallest_in () {
        ls -S1r "$@" | head -n1
}

where -S is an abbreviation for --sort=size
      -1 is an abbreviation for --format=single-column
and   -r is an abbreviation for --reverse

Just found it might be interesting to someone ...

Marc

-- 
Marc Mutz <[EMAIL PROTECTED]>        http://marc.mutz.com/Encryption-HOWTO/
University of Bielefeld, Dep. of Mathematics / Dep. of Physics

PGP-keyID's:   0xd46ce9ab (RSA), 0x7ae55b9e (DSS/DH)



-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to [EMAIL PROTECTED]
Please read the FAQ at http://www.linux-learn.org/faqs

Reply via email to