Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^4: What does ">>" do? (And other stat questions)

by three18ti (Scribe)
on Nov 03, 2013 at 00:57 UTC ( #1061002=note: print w/replies, xml ) Need Help??

in reply to Re^3: What does ">>" do? (And other stat questions)
in thread What does ">>" do? (And other stat questions)

Awesome! Thanks so much for the explanation.

I think I understand everything except for why we're essentially throwing away the first four bits. Why are they there to begin with? And why don't we need them?

Thanks again, this is awesome

  • Comment on Re^4: What does ">>" do? (And other stat questions)

Replies are listed 'Best First'.
Re^5: What does ">>" do? (And other stat questions)
by Laurent_R (Abbot) on Nov 03, 2013 at 09:45 UTC

    The file mode given by stat[2] consists of two distinct pieces of information: the file type and the file permissions. If you want to see only the permissions, you have to mask off the file type portion of the mode. This is what the bitwise and (&) with 07777 does, as shown in my previous post.

    The file type corresponds to the first character displayed on a ls -l command under the Unix shell prompt:

    $ ls -l /etc/passwd -rw-r--r-- 1 Laurent root 841 9 mai 23:24 /etc/passwd
    The initial dash (-) displayed above says it is a regular file, a d would indicate a directory, a l a symbolic link, an s a socket, etc. This information is the file type displayed in the first half byte (four bits) of the file mode reported by stat[2].

      Ah Ha!

      So cool! Thanks for the explanation

      So following that logic, could we then mask off the first four bits with 077777?

      but that would only be 15 bits, not 16, so probably not.

      (Side note, I thought there were 8 bits to a byte?)

        Of course you are right, a byte is (usually) 8 bits, I meant to say the first half byte, but my fingers did not obey my mind. I made the correction in my post.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1061002]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2017-08-21 14:16 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (324 votes). Check out past polls.