Write A Program To Check File Permission Of The File Gain Infiniti

Write A Program To Check File Permission Of The File


ls -l $1 | awk ' NF > 2    {    print "FileName = ",$NF

                if(substr($1,1,1) == "d")
                print "FileType = Directory"
                else
                print "FileType = RegularFile"
               
                printf "%s ","Owner Permissions --> "
                if(substr(substr($1,2,3),1,1) == "r")
                printf "%s ","Read"
                else
                printf "%s ","!Read"
                if(substr(substr($1,2,3),2,1) == "w")
                printf "%s ","Write"
                else
                printf "%s ","!Write"
                if(substr(substr($1,2,3),3,1) == "x")
                printf "%s\n","Execute"
                else
                printf "%s\n","!Execute"

                printf "%s ","Group Permissions --> "
                if(substr(substr($1,5,3),1,1) == "r")
                printf "%s ","Read"
                else
                printf "%s ","!Read"
                if(substr(substr($1,5,3),2,1) == "w")
                printf "%s ","Write"
                else
                printf "%s ","!Write"
                if(substr(substr($1,5,3),3,1) == "x")
                printf "%s\n","Execute"
                else
                printf "%s\n","!Execute"

                printf "%s ","Other Permissions --> "
                if(substr(substr($1,8,3),1,1) == "r")
                printf "%s ","Read"
                else
                printf "%s ","!Read"
                if(substr(substr($1,8,3),2,1) == "w")
                printf "%s ","Write"
                else
                printf "%s ","!Write"
                if(substr(substr($1,8,3),3,1) == "x")
                printf "%s\n","Execute"
                else
                printf "%s\n","!Execute"


                }'



OUTPUT:-

#!/bin/bash
#root@slack-linunx:~/scripts# ./checkPermissions.sh testFile
#FileName =  testFile
#FileType = RegularFile
#Owner Permissions -->  Read Write !Execute
#Group Permissions -->  Read !Write !Execute
#Other Permissions -->  !Read !Write !Execute
#root@slack-linunx:~/scripts#

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 

Design By Manish and Ranjan