##Another example: FOR Loop: Get all test files size
[prabhucloudxlab@cxln4 ~]$ du -h student1.txt
4.0K student1.txt
[prabhucloudxlab@cxln4 ~]$ du -h student1.txt | awk '{print $1}'
4.0K
=================================================================
[prabhucloudxlab@cxln4 ~]$ cat>4sh.sh
#! bin/bash
# FOR Loop: Get all test files size
for i in *.txt; do
size=$(du -h "$i")
echo "file size is $size"
done
[prabhucloudxlab@cxln4 ~]$ sh 4sh.sh
file size is 0 hive_table_output1.txt
file size is 4.0K hive_table_output.txt
file size is 4.0K outmerge.txt
file size is 4.0K retail_db_tables.txt
file size is 24K sample-snappy.txt
file size is 4.0K sample.txt
file size is 4.0K student1.txt
file size is 12K student_union1.txt
file size is 12K student_union.txt
file size is 0 test1.txt
file size is 0 test2.txt
file size is 0 test3.txt
file size is 0 test4.txt
file size is 0 test5.txt
=================================================================
#! bin/bash
# FOR Loop: Get all test files size and Move 0KB files to seperate folder
value=0;
for i in /home/prabhucloudxlab/* .txt; do
duu=$(du -h "$i")
if [ $duu==$value ]
then
echo "0 KB files $i"
mv -f $i /home/prabhucloudxlab/prabhu
fi
done