How to get from '-rw-r--r--' back to 33188? How to get from '-rw-r--r--' back to 33188? unix unix

How to get from '-rw-r--r--' back to 33188?


Python is open-source, you can just read the source code for the stat module and write the inverse function.

See: https://github.com/python/cpython/blob/master/Lib/stat.py#L112

import statdef un_filemode(mode_str):    mode = 0    for char, table in zip(mode_str, stat._filemode_table):        for bit, bitchar in table:            if char == bitchar:                mode |= bit                break    return mode

Note that I'm being "naughty" and accessing private members of the stat module. The usual caveats apply.

Also note that the documentation for stat.filemode is incorrect anyway, since 0o100000 is technically not part of the file mode, it is the file type S_IFREG. From inode(7):

POSIX refers to the stat.st_mode bits corresponding to the mask S_IFMT (see below) as the file type, the 12 bits corresponding to the mask 07777 as the file mode bits and the least significant 9 bits (0777) as the file permission bits.