Chmod

如何通過字元串獲取權限號:-rw-r–r–

  • September 27, 2021

我需要設置相同的 chmod,如何獲取**-rw-r–r– 的**數字?

請檢查stat輸出:

# 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: -

r這些數字是通過將、w和表示的二進制值相加來計算的x

r = 100b = 4
w = 010b = 2
x = 001b = 1

在每一組。在您的情況下,-rw-r--r--將由

6(r+w=4+2)4(r=4)4(r=4)

所以相關的命令是

chmod 644 path/to/file

引用自:https://unix.stackexchange.com/questions/39710