Shell Scripting - File test operators
Check whether file found or not
#!/usr/bin/bash
echo -e "Enter name of th file:\c"
read file_name
if [ -e $file_name ]
then
echo "$file_name found"
else
echo "$file_name not found"
fi
Check weather directory found or not
if [ -d $file_name ]
character special file using -c
if [ -c $file_name ]
Block special file using -b
if [ -b $file_name ]
Check weather file is empty or not
if [ -s $file_name ]
#!/usr/bin/bash
echo -e "Enter name of th file:\c"
read file_name
if [ -s $file_name ]
then
echo "$file_name not empty"
else
echo "$file_name empty"
fi
File read permission -r and write permission -w