awk

Awk dumps.

Count number of bytes in multiple directories

I have been busy moveing (scp-ing/reorganising) large numer of databases over the network, this little awk script makes me able to count the number of bytes and thus check if my nighlty scp’s didn’t miss a byte. (or two)

/cygdrive/c/oracle/oradata/DB01/DB01
$ find . -name "*DBF" -exec ls -l {} \;
-rwxrwx--- 1 Administrators SYSTEM 10493952 Oct  9 16:49 ./DB01/DATAFILE/O1_MF_TEST_3HSWQYNH_.DBF
-rwxrwx--- 1 Administrators SYSTEM 104865792 Oct  9 16:49 ./EXAMPLE01.DBF
-rwxrwx--- 1 Administrators SYSTEM 293412864 Oct  9 16:49 ./P1PERG001.DBF
-rwxrwx--- 1 Administrators SYSTEM 104865792 Oct  9 16:49 ./P1PERG002.DBF
-rwxrwx--- 1 Administrators SYSTEM 272637952 Oct 13 08:34 ./SYSAUX01.DBF
-rwxrwx--- 1 Administrators SYSTEM 513810432 Oct  9 16:49 ./SYSTEM01.DBF
-rwxrwx--- 1 Administrators SYSTEM 20979712 Oct 13 08:36 ./TEMP01.DBF
-rwxrwx--- 1 Administrators SYSTEM 47194112 Oct  9 16:49 ./UNDOTBS01.DBF
-rwxrwx--- 1 Administrators SYSTEM 5251072 Oct  9 16:49 ./USERS01.DBF

/cygdrive/c/oracle/oradata/DB01/DB01
$ find . -name "*DBF" -exec ls -l {} \; | awk '
> BEGIN { BYTES = 0 }
> { BYTES = BYTES + $5 }
> END { print "Total number of bytes = " BYTES}'
Total number of bytes = 1373511680

/cygdrive/c/oracle/oradata/DB01/DB01
$

Even shorter.

find /m*/oradata/ai018001/ -name "*dbf" -exec ls -l {} \; | awk '{B+=$5} END {print B}'

Number format…

find /m*/oradata/ai018001/ -name "*dbf" -exec ls -l {} \; | awk '{B+=$5} END {printf( "%d", B); print ""}'

Leave a Reply

Helpful? - leave your note below so I can brag

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>