Find the answer to your Linux question:
Results 1 to 6 of 6
I've been using Linux for two years, as a server, and you'd think I would have stumbled across a answer to this by now. Documentation with various scripts will tell ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2004
    Posts
    4

    Why are some chmod commands 4 digits?


    I've been using Linux for two years, as a server, and you'd think I would have stumbled across a answer to this by now. Documentation with various scripts will tell you to chmod a file/folder to a 4-digit value. I understand 3-digit chmod basics but the fourth number is a mystery to me - something to do with ownership (like a "chown" value)????

    Thanks for any input.


    Guy Merritt
    Flint, MI

  2. #2
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    Location
    St. Petersburg, FL
    Posts
    5,035
    do you mean the single character that comes at the beginning?

    the first letter is:

    d:directory
    -:file
    c:char device
    b:block device
    l:symbolic link
    s:socket
    = or p:FIFO

  3. #3
    Linux Guru Flatline's Avatar
    Join Date
    Feb 2005
    Posts
    2,204
    Actually, chmod uses 4 digits for permissions; if you give chmod only three digits, then the highest bit is assumed to be zero. So, "chmod 0777" is the same thing as "chmod 777".
    That first "hidden" bit allows you to set the following:
    4=setUID
    2=setGID
    1=sticky
    There are two major products that come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence.

    - Jeremy S. Anderson

  4. #4
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496

    Re: Why are some chmod commands 4 digits?

    Nevermind. I was apparently explaining the wrong thing.
    Registered Linux user #270181
    TechieMoe's Tech Rants

  5. #5
    Linux Guru Flatline's Avatar
    Join Date
    Feb 2005
    Posts
    2,204
    Good explanation Techiemoe, but the bit is not the "directory bit". It is there for SUID, SGID, and stickybits, as I stated above.
    There are two major products that come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence.

    - Jeremy S. Anderson

  6. #6
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Quote Originally Posted by lakerdonald
    the first letter is:

    d:directory
    -:file
    c:char device
    b:block device
    l:symbolic link
    s:socket
    = or p:FIFO
    These are output by "ls". If the SETUID or SETGID bit is set it'll show as 's' if the execute bit is also set, or 'S' otherwise in the "owner" and "group" sections respectively, and the sticky bit will show as 't' if execute is also set , 'T' otherwise in the execute bit position of the "other" bits. I prefer to refer the the sticky bit as the "tacky" bit, as that starts with a t, and stops people referring erroneously to the SET[UG]ID as "sticky", just because it starts with 's'.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •