Readin File permissions?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thaiZilla
    New Member
    • Jan 2008
    • 16

    Readin File permissions?

    How do i read a file permission?

    i know that ls -l *filename* will list all information about the file including file permissions eg -rwxr-xr-x 1 norman.thai users 187 Jan 15 10:33 firstline...

    how do i read just the file permission tho to use be used as a variable...
    -rwxr-xr-x

    i also understand that the file permissions can be read as binary 000 000 000...
  • ashitpro
    Recognized Expert Contributor
    • Aug 2007
    • 542

    #2
    Originally posted by thaiZilla
    How do i read a file permission?

    i know that ls -l *filename* will list all information about the file including file permissions eg -rwxr-xr-x 1 norman.thai users 187 Jan 15 10:33 firstline...

    how do i read just the file permission tho to use be used as a variable...
    -rwxr-xr-x

    i also understand that the file permissions can be read as binary 000 000 000...
    use this command

    ls -l *filename* | awk {'print $1'}

    Comment

    • thaiZilla
      New Member
      • Jan 2008
      • 16

      #3
      Originally posted by ashitpro
      use this command

      ls -l *filename* | awk {'print $1'}
      Hey thanks for your reply. However i've not used awk or sed before and i'm not suppose to use it for this exercise. The full task is to use a file as an argument then display the permissions in a certain format like so :-

      READ WRITE EXECUTE
      OWNER LEE.BALLANCORE YES YES NO
      GROUP USERS YES NO NO
      EVERYBODY NO NO NO

      i jus want to know how to read the permissions in binary so i can use if statements to create the text...if ya get me, sorry if it sounds a bit of a woffle

      Comment

      • ashitpro
        Recognized Expert Contributor
        • Aug 2007
        • 542

        #4
        Originally posted by thaiZilla
        Hey thanks for your reply. However i've not used awk or sed before and i'm not suppose to use it for this exercise. The full task is to use a file as an argument then display the permissions in a certain format like so :-

        READ WRITE EXECUTE
        OWNER LEE.BALLANCORE YES YES NO
        GROUP USERS YES NO NO
        EVERYBODY NO NO NO

        i jus want to know how to read the permissions in binary so i can use if statements to create the text...if ya get me, sorry if it sounds a bit of a woffle
        If I am not wrong, you are trying to achieve this with C code..correct me If I am wrong.

        Check out this link..

        http://www.gnu.org/software/libc/manual/html_node/Permission-Bits.html#Permi ssion-Bits
        Here are enough macros to read the permission for file.

        If you are doing this under shell script..then no option other that 'awk'.

        Comment

        • numberwhun
          Recognized Expert Moderator Specialist
          • May 2007
          • 3467

          #5
          Another good link to read is this one.

          Regards,

          Jeff

          Comment

          Working...