---------------------------------------------------
| Date: 2001-11-23 02:09:44 |
| Filename: filetest.sh |
| Author: detour@metalshell.com |
| |
| http://www.metalshell.com/ |
---------------------------------------------------
#!/bin/bash
#
# File stats written by detour@metalshell.com
#
# Example of file testing with bash
#
# -O $file true if owned by EUID
# -G $file true if owned by EGID
# -e $file exists
# -z $file zero file
# -n $file nonzero file
# -r $file readable
# -w $file writeable
# -x $file executable
# -f $file plain file
# -d $file directory
# -L $file symbolic link
# -p $file named pipe or FIFO
# -S $file socket
# -b $file block special file
# -c $file character special file
# -u $file setuid
# -g $file setgid
# -k $file sticky
# -t $file true if opened to a tty
#
# http://www.metalshell.com/
#
echo -n "Enter the filename to test: "
read
if [ -e $REPLY ]; then
echo "## FILE STATUS OF $REPLY ##"
if [ -z $REPLY ]; then
echo "# File is empty."
fi
if [ -n $REPLY ]; then
echo "# File is not empty."
fi
if [ -r $REPLY ]; then
echo "# You have permission to read this file."
fi
if [ -w $REPLY ]; then
echo "# You have permission to write to this file."
fi
if [ -x $REPLY ]; then
echo "# You have permission to execute this file."
fi
if [ -f $REPLY ]; then
echo "# This is a plain file."
fi
if [ -d $REPLY ]; then
echo "# $REPLY is a directory"
fi
else
echo "File not found. Exiting."
exit 1
fi
exit 0