all Python 3osfunction
os.path.getatime
os.path — metadata (stat)
Return the last-access time of a file (seconds since the epoch).
Syntax
os.path.getatime(path)
The value is often untrustworthy: Linux usually mounts disks with relatime or noatime, so access time is updated rarely or not at all. Basing logic such as "delete files not opened for a long time" on it is therefore risky. Reading the file itself, where atime is updated, moves the value.
Examples
import os
import time
print(os.path.getatime(os.__file__) > 0) # → True
print(os.path.getatime(os.__file__) == os.stat(os.__file__).st_atime) # → True: getatime — это просто os.stat(path).st_atime
print(time.ctime(os.path.getatime(os.__file__))) # → время последнего доступа в читаемом виде, например Tue Jul 21 10:15:03 2026 (на ФС с noatime/relatime оно не обновляется при каждом чтении)
print(os.path.getatime(os.__file__) <= time.time()) # → True: время доступа не может быть в будущем
print(os.path.getatime('нет-такого-файла')) # → FileNotFoundError
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy