How to get permission number by string : -rw-r--r--

  • I need to set the same chmod, how to get number for -rw-r--r-- ?

    Programmatically or do you just need to know how to translate?

    I'm lazy to translate :) stat is fine for a moment for me.

    What do you mean by “set the same”? Do you already have a file with -rw-r--r-- permission and want to set another file with the same permissions? Then see if your `chmod` supports `--reference`: “--reference=RFILE use RFILE's mode instead of MODE values” – man chmod.

    What Unix are you using?

  • lik

    lik Correct answer

    8 years ago

    Please check stat output:

    # stat .xsession-errors 
      File: ‘.xsession-errors’
      Size: 839123          Blocks: 1648       IO Block: 4096   regular file
    Device: 816h/2070d      Inode: 3539028     Links: 1
    Access: (0600/-rw-------)  Uid: ( 1000/     lik)   Gid: ( 1000/     lik)
    Access: 2012-05-30 23:11:48.053999289 +0300
    Modify: 2012-05-31 07:53:26.912690288 +0300
    Change: 2012-05-31 07:53:26.912690288 +0300
     Birth: -

    `stat -c %a /path/to/file` is the magic trick you need.

    and the answer is in the Access block there above. The file he used in the example has different access set then the one in the question. the one in the question would have shown Access: (0644/-rw-r--r--)

License under CC-BY-SA with attribution

Content dated before 6/26/2020 9:53 AM