Click to See Complete Forum and Search --> : How to determine filesize using BASH


bgunn
01-20-2003, 12:21 AM
Hi All

I am trying to write a script that tests the size of a file. I have tried using this line to assign the file size to a variable, but it wont work. It just says

" filesize: line 7: | cut -f 5 -d : command not found "

Here is the script:
----------------------------------
#!/bin/bash

echo
echo -n "Enter file name "
read FILENAME

SIZE='ls -l $FILENAME | tr -s ' ' | cut -f 5 -d ' ''
echo "Size of '$FILENAME' is $SIZE"
exit
------------------------------------

Any suggestions?

Thanks, Ben

bgunn
01-20-2003, 12:27 AM
Problem solved

I was using " ' " instead of " ` " for the command substitution.

Bokkenka
01-20-2003, 12:34 AM
A easier command to get the size...

du -b $FILENAME | cut -f 1

Bokkenka
01-20-2003, 12:56 AM
OK, maybe not... It's the space it takes up on the disc, not the actual size.