ファイルのタイムスタンプを秒単位で扱う方法

トラブルシュートの中で、秒単位で事象の前後関係を洗う必要があったため、Linuxでファイルを秒単位のタイムスタンプで扱う方法を調べてみた。lsコマンドの他、touchコマンドを使うパターン、findとxargsの組み合わせなどがありそう。

  • lsコマンドの「--full-time」オプションを使用した例


[root@centos4 conf.d]# ls -l --full-time
合計 40
-rw-r--r-- 1 root root 392 2008-01-14 22:22:06.000000000 +0900 README
-rw-r--r-- 1 root root 3492 2005-06-10 22:35:07.000000000 +0900 auth_mysql.conf
-rw-r--r-- 1 root root 448 2007-09-21 08:41:40.000000000 +0900 php.conf
-rw-r--r-- 1 root root 12321 2008-06-13 12:06:46.000000000 +0900 ssl.conf
-rw-r--r-- 1 root root 1181 2005-08-22 11:04:19.000000000 +0900 subversion.conf
drwxr-xr-x 2 root root 4096 2008-06-12 16:19:54.000000000 +0900 svnconf
-rw-r--r-- 1 root root 299 2008-01-14 22:22:06.000000000 +0900 welcome.conf

  • touchコマンドを使用した例


$ touch -am -t 200001010000.00 *

  • findとxargsを使用した例


$ find /path/to -type f | xargs touch -am -t 200001010000.00