File
#! /bin/bash
read -p "give me the file name? " myfile
# this will make the script interactive
# condition to check if a file exists
# myfile=new.txt
# -e for exists
if [ -e $myfile ]; then
echo "$myfile exists"
fi
# negate a condition
if [ ! -e $myfile ]; then
echo "$myfile does not exist"
fi
# check if is directory
# -d for directory
if [ -d $myfile ]; then
echo "$myfile is a directory"
else
echo "$myfile is not a directory"
fi
# -r is readable
if [ -r $myfile ]; then
echo "$myfile is readable"
fi
-w is writeable
-r is writeable
if [ -w $myfile ]; then echo “$myfile is writeable” else echo “$myfile is not writeable” fi
-x is executable
if [ -x $myfile ]; then echo “$myfile is executable” else echo “$myfile is not executable” fi
-s is not empty
if [ -s $myfile ]; then echo “$myfile is NOT empty” else echo “$myfile is empty” fi
-f for if it’s a regular file
if [ -f $myfile ]; then echo “$myfile is a regular file” else echo “$myfile is not a regular file” fi