hi i want to find the size of a folder and assign it to a variable and then compare if it is greater than 1 gb.
i am doin this script, but it is throwing error....
#!/bin/ksh
cd . | du -s | size = awk '{print $1}'
if size >= 112000
then
echo size high
fi
ERROR :
size: awk: cannot open
size: {print $1}: cannot open
size: 112000: cannot open
@Nithz
In future posts, please post the current version of your script along with any matching error messages.
You are quite a long way adrift with syntax. Note that when assigning variables there is no space character either side of the equals sign.
This should get you past the syntax errors.
#!/bin/ksh
size=$(du -s | awk '{print $1}')
if [ ${size} -ge 112000 ]
then
echo "${size} high"
fi
Now! I wonder where the number 112000 came from? The units of the output from "du -s" are in "512 byte blocks".
Using the unix in-line calculator "bc" I get a different value for the number of 512 byte chunks in a Gigabyte.
echo "(1024*1024*1024)/(512)"|bc
2097152
The units of "du -sk" are easier to work with. See the "man" page for "du".