Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a zenity message box in a script

zenity --info --text='done' > /dev/null 2>&1

I need to pop up a message, e.g.: "file is smaller then 30 KBytes!" when a file is smaller then 30 KBytes.

How could i write an "if then else" script to pop up a zenity message, when e.g.: "FILE" is smaller then 30 KByte?

Thank you!

share|improve this question

3 Answers 3

up vote 3 down vote accepted
#!/bin/bash

if [ $(stat --printf="%s" FILENAME) -lt 30720 ]; then
    zenity --info --text='file is smaller then 30 KBytes!' > /dev/null 2>&1
fi
share|improve this answer
    
wow! :O thank you for all the answers! –  LanceBaynes Feb 28 '11 at 12:55

These examples use syntax that is specific to more modern shells such as Bash, ksh and zsh.

Some systems don't have stat and you shouldn't parse ls.

result=$(find . -maxdepth 1 -name "$file" -size -30k)
if [[ ${result##*/} = $file ]]
then
    zenity --info --text='The file is smaller then 30 KBytes!' > /dev/null 2>&1
fi

Where "30k" equals 30720. If you'd prefer, you can use -size -30000c.

If you do have stat:

size=$(stat -c '%s' "$file")
if (( size < 30720 ))    # or you could use 30000
then
    zenity --info --text='The file is smaller then 30 KBytes!' > /dev/null 2>&1
fi
share|improve this answer
SIZE=`ls -l $1 | awk '{print $5}'`

if [ $SIZE -lt 30720 ]
then
        zenity --info --text='File is smaller than 30KB' > /dev/null 2>&1
fi
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.