1

rpm --dump will print file mode in 7-digit octal format:

$ rpm -q --dump rpm | grep -E '/usr/bin/rpmdb|/var/lib/rpm ' | cut -d' ' -f1,5
/usr/bin/rpmdb 0100755
/var/lib/rpm 040755
$

What do all those digits mean? I guess some of it will be related to file type, but can I reproduce the same string given I have an existing file and standard command line tools (+ perl/python, etc. if necessary)?

I've looked at rpm(1), which does not reveal anything (only calls the field "mode"), and stat(1), which only mentions the usual 4-digit mode. Closest I got is this other question about 6-digit format on AIX.

Edit: I just noticed it's sometimes 6 digits; question remains mostly the same, though.

1

1 Answer 1

6

This is the st_mode field of the stat structure: it encodes both the file type and the mode bits. Do man 2 stat (or perhaps man 7 inode) on a linux system and search for the section entitled "The file type and mode". E.g. 0100755 means "regular file with mode 755" and 040755 means "directory with mode 755".

BTW, the leading 0 means "octal" since these values are so specified in the header files. The number of digits is irrelevant: it's just what is needed to contain the full value.

5
  • 1
    Nice, turns out that stat provides this as %f, so I can even get the mode by printf '0%o\n' "0x$(stat -c %f /path/to/file)" | sed 's/^00*/0/' Feb 21, 2018 at 17:49
  • Also stat(2) provides the details. (inode(7) was not available on my system.) Feb 21, 2018 at 17:55
  • That's right: stat(1) gives you hex so you need to convert.
    – NickD
    Feb 21, 2018 at 18:01
  • I'm on Fedora 27: stat(2) is where I looked first, but it referred me to inode(7) :-) I'll edit.
    – NickD
    Feb 21, 2018 at 18:02
  • You could also try ... $(stat --printf="%#f" /path/to/file) ....
    – NickD
    Feb 21, 2018 at 18:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .