Shell script to display file permissions
Script:
#displays a list a list of files in directory via arguments read,write& execute
#echo Enter the directory name :
read dir
if [ -d $dir ]
then
cd $dir
ls>f
exec<f
while read line
do
if [ -f $line ]
then
if [ -r $line ] && [ -w $line ] && [ -x $line ];
then
echo $line has all permissions
else
echo $line has not all permissions
fi
fi
done
fi
Output:
root@root:~/os/test# chmod a+rwx test2
root@root:~/os/test# ls -l
total 16
-rw-r--r-- 1 root root 20 Aug 30 21:09 f
---------- 1 root root 255 Jul 14 19:00 test1
-rwxrwxrwx 1 root root 395 Jul 14 19:12 test2
-rw-r--r-- 1 root root 395 Jul 14 19:13 test3
root@root:~/os# sh 2c.sh
Enter the directory name
test
f did not have all permissions
test1 did not have all permissions
test2 has all permissions
test3 did not have all permissions
#displays a list a list of files in directory via arguments read,write& execute
#echo Enter the directory name :
read dir
if [ -d $dir ]
then
cd $dir
ls>f
exec<f
while read line
do
if [ -f $line ]
then
if [ -r $line ] && [ -w $line ] && [ -x $line ];
then
echo $line has all permissions
else
echo $line has not all permissions
fi
fi
done
fi
Output:
root@root:~/os/test# chmod a+rwx test2
root@root:~/os/test# ls -l
total 16
-rw-r--r-- 1 root root 20 Aug 30 21:09 f
---------- 1 root root 255 Jul 14 19:00 test1
-rwxrwxrwx 1 root root 395 Jul 14 19:12 test2
-rw-r--r-- 1 root root 395 Jul 14 19:13 test3
root@root:~/os# sh 2c.sh
Enter the directory name
test
f did not have all permissions
test1 did not have all permissions
test2 has all permissions
test3 did not have all permissions
Comments
Post a Comment