最新の起動時間を含むファイル

最新の起動時間を含むファイル

コンピュータを最後に起動した時刻を記録するファイルはありますか?私はのようなシェルコマンドを使うのが好きではありませんwho -b

ベストアンサー1

おそらく/var/run/utmp/var/run/utmpx

私はstraceを使ってどのファイルにアクセスしているかを確認します。

$ strace who -b  &| grep open
...
access("/var/run/utmpx", F_OK)          = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/var/run/utmp", O_RDONLY|O_CLOEXEC) = 3
...

man 5 utmpこれにより、ログイン履歴を含む内容を読むことができます。

また、マニュアルにBOOT_TIMEがあるという情報を取得することもできます。

       The file is a sequence of utmp structures, declared as follows  in  <utmp.h>  (note
       that  this is only one of several definitions around; details depend on the version
       of libc):

           /* Values for ut_type field, below */

           #define EMPTY         0 /* Record does not contain valid info
                                      (formerly known as UT_UNKNOWN on Linux) */
           #define RUN_LVL       1 /* Change in system run-level (see
                                      init(1)) */
           #define BOOT_TIME     2 /* Time of system boot (in ut_tv) */

ウィキペディアでこれについての詳細を読むことができます。https://en.wikipedia.org/wiki/Utmp

おすすめ記事