1

Is there a man page for the file permission numbers?

I'm specifically talking about

r = 4
w = 2
x = 1

I can never remember them and I have to google it every time I need to set permissions besides 755. I don't think I'm alone, either, since there's even a site that calculates the number for you.

I just realized the man page for chmod doesn't have any description of the numbers and I can't figure out what other page would have them. I guess an info page would work as well, since apparently it comes pre-installed (I have arch; I'd have thought I'd have had to install that one myself--apparently not). It would be a lot easier for me if I could just refer to an 'on-line' man page (I use 'on-line' in the sense used in man man).

  • 3
    I am having trouble finding a man page that doesn't list the mode bits in it. The GNU man page it sounds like you'd have certainly does: "The second digit selects permissions for the user who owns the file: read (4), write (2), and execute (1)". Are you sure it's not there? – Michael Homer Dec 31 '18 at 22:10
  • @MichaelHomer Yeah, I should have read more carefully. I was looking for a table. Terrible laziness on my part all day today. – malan Dec 31 '18 at 22:14
  • 5
    I remember it in terms of postion, rwx, and convert from binary. So "r" is 100, "w" is 010, "x" is 001. In binary that means r=4, w=2, x=1. When you see enough ls -l output that "rwx" order eventually gets stuck in your mind :-) – Stephen Harris Dec 31 '18 at 22:19
  • @StephenHarris I very much expected this: someone to answer the question and then give me a helpful mnemonic so that I don't even need to look it up anymore. Thanks! – malan Dec 31 '18 at 22:22
  • 1
    Why on Earth do people use numbers to set file permissions? "chmod [ugo][+-][rwx] works perfectly well for most cases (and there are options for less common ones - read the man page), and is almost impossible to forget. – jamesqf Jan 1 at 4:20
4

man chmod is likely to give you the command line tool. This may include some text that is easy to miss

The second digit selects permissions for the user who owns the file: read (4), write (2), and execute (1)

If you do man 2 chmod then you get the system call that actually does the work. This is harder to read, but does include the magic numbers:

   S_IRUSR  (00400)  read by owner
   S_IWUSR  (00200)  write by owner
   S_IXUSR  (00100)  execute/search  by owner ("search" applies for direc-
                     tories, and means that entries within  the  directory
                     can be accessed)
   S_IRGRP  (00040)  read by group
   S_IWGRP  (00020)  write by group
   S_IXGRP  (00010)  execute/search by group
   S_IROTH  (00004)  read by others
   S_IWOTH  (00002)  write by others
   S_IXOTH  (00001)  execute/search by others

It also provides some other magic values:

   S_ISUID  (04000)  set-user-ID  (set  process  effective  user   ID   on
                     execve(2))

   S_ISGID  (02000)  set-group-ID  (set  process  effective  group  ID  on
                     execve(2);  mandatory  locking,   as   described   in
                     fcntl(2);  take a new file's group from parent direc-
                     tory, as described in chown(2) and mkdir(2))

   S_ISVTX  (01000)  sticky bit (restricted deletion flag, as described in
                     unlink(2))
  • Any idea what the S_I prefix stands for? – undercat Dec 31 '18 at 22:12
  • 4
    @undercat I always guessed it was "stat" "inode"... but that's just a guess and probably totally wrong :-) – Stephen Harris Dec 31 '18 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.