File test operators

#! /bin/bash

if [ -e abc.txt ] #file or a directory exist
then
    echo File/dir exist
fi
if [ -e xyz ]
then 
    echo File/dir exist
fi

if [ -f abc.txt ] # file exist
then
    echo File exist
fi

if [ -d xyz ] # directory exist
then
    echo Dir exist
fi

if [ -s abc.txt ] # checking if dat exist in file
then
    echo Data Exist in abc.txt
fi

if [ -r abc.txt ] # checking read permission
then
    echo Read permission exist for abc.txt
fi

if [ -w abc.txt ] # checking write permission
then
    echo Write permission exist for abc.txt
fi

if [ -x abc.txt ] # Checking execute permission
then
    echo Execute permssion exist for abc.txt
fi

if [ -b abc.txt ] # b for binary file
then
    echo Abc.txt is a block special file
fi

if [ -c abc.txt ] # c for character file
then
    echo Abc.txt is a character special file
fi

Leave a Comment