You are on page 1of 2

Test cmd

gedit example3 &


clear
echo -n "Enter file name "
read fileName
if test -s $fileName
then
echo "Exists"
else
echo "Does not exist"
fi
chmod 755 example3
ls
Create a new file with nothing so it's size is zero:
touch file3
./example3
Ex-2: Write a prog to determine if a file is a normal file.
gedit ex2 &
clear
echo -n "Enter file name "
read fileName
if test -f $fileName
then
echo "File is ordinary"
fi
if test-r $fileName
then
echo "$fileName is not readable"
fi
chmod 755 ex2
./ex2
Ex-3: Check each files specific directory.
read every file in a directory into a list and redirect to a file.
ls > newFile
cat newFile
gedit ex3 &
clear
echo -n "Enter directory "
read myDir
cd $myDir
ls > tmpFile
((f=0)); ((d=0))
while read fileName
do
if test -f $fileName
then
((f++))
fi

if test -d $fileName
then
((d++))
fi
done < tmpFile; ((f--))
echo "Number of directories is $d"
echo
echo "Number of files is $f"
rm tmpFile

You might also like