Python Glossary Русский

Python 3.15+Linuxosfunction

os.statx()

os — filesystem

File information via the Linux statx system call: request only the fields you need with a mask, and get the file's creation time.

Syntax

os.statx(path, mask, *, flags=0, dir_fd=None, follow_symlinks=True)

os.stat returns a fixed set of fields and does not know a file's creation time on Linux. statx takes a mask built from os.STATX_* constants, for example os.STATX_BTIME for creation time or os.STATX_SIZE for size, and returns an os.statx_result. The kernel may return less than asked for, or more: the stx_mask field shows what was actually retrieved, and missing fields are None. It works only on Linux 4.11+ with glibc 2.28+; portable code stays with os.stat.

Examples

import os
with open('demo.txt', 'w') as f:
    f.write('abc')
st = os.statx('demo.txt', os.STATX_SIZE)
print(st.stx_size)  # → 3
print(bool(st.stx_mask & os.STATX_SIZE))  # → True

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy