Archive

Posts Tagged ‘script’

Bir dosyanın boş olup olmadığını kontrol etme

November 7th, 2012 No comments

Shell script yazarken bir dosyanın boş olup olmadığını kontrol etmemiz gerekebilir. Bunu yapmak için birkaç yöntem yazacağım.

satirsayisi=`wc  -l 194.27.108.90  | awk '{split($0,a," "); print a[1]}'`
if [ $satirsayisi == 0 ]; then echo "dosya bos"; fi
if [ -z $(cat dosyaadi) ]; then echo "dosya bos"; fi
if [ -z `cat dosyaadi` ]; then echo "dosya bos"; fi

Ve en güzeli

if [ -s dosyaadi ]; then echo "Dosya dolu"; else echo "Dosya bos"; fi
Categories: Gezegen, Linux Tags: , , , , ,