Saturday, April 28, 2012

Shell script: check if two files are havings same permissions or not

This is a small script to check if two given files permissions are same or not


#!/bin/bash
#Purpose: To check two given files are having same permissions or not
#Author: Surendra Anne(surendra@linuxnix.com)
#Date:2012-04-24
#Modified:::


read -p "Enter two files with their paths" FILE1 FILE2


PERM1=$(stat --printf="%a" $FILE1)
PERM2=$(stat --printf="%a" $FILE2)


if [ $PERM1 -eq $PERM2 ]
then
echo "Both the files have same permissions: $PERM1"
else
echo "The given files have different permissions"
fi


Some of the tools used here are
read command
Command substitution
stat command
square brackets
if statement

0 comments:

Post a Comment