How to get file creation date/time in Bash/Debian?

后端 未结 12 1771
有刺的猬
有刺的猬 2020-11-28 23:00

I\'m using Bash on Debian GNU/Linux 6.0. Is it possible to get the file creation date/time? Not the modification date/time. ls -lh a.txt and stat -c %y a.

12条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 23:39

    You can find creation time - aka birth time - using stat and also match using find.
    We have these files showing last modified time:

    $ ls -l --time-style=long-iso | sort -k6
    total 692
    -rwxrwx---+ 1 XXXX XXXX 249159 2013-05-31 14:47 Getting Started.pdf
    -rwxrwx---+ 1 XXXX XXXX 275799 2013-12-30 21:12 TheScienceofGettingRich.pdf
    -rwxrwx---+ 1 XXXX XXXX  25600 2015-05-07 18:52 Thumbs.db
    -rwxrwx---+ 1 XXXX XXXX 148051 2015-05-07 18:55 AsAManThinketh.pdf
    

    To find files created within a certain time frame using find as below.
    Clearly, the filesystem knows about the birth time of a file:

    $ find -newerBt '2014-06-13' ! -newerBt '2014-06-13 12:16:10' -ls 
    20547673299906851  148 -rwxrwx---   1 XXXX XXXX   148051 May  7 18:55 ./AsAManThinketh.pdf
    1407374883582246  244 -rwxrwx---   1 XXXX XXXX   249159 May 31  2013 ./Getting\ Started.pdf
    


    We can confirm this using stat:

    $ stat -c "%w %n" * | sort
    2014-06-13 12:16:03.873778400 +0100 AsAManThinketh.pdf
    2014-06-13 12:16:04.006872500 +0100 Getting Started.pdf
    2014-06-13 12:16:29.607075500 +0100 TheScienceofGettingRich.pdf
    2015-05-07 18:32:26.938446200 +0100 Thumbs.db
    


    stat man pages explains %w:

    %w     time of file birth, human-readable; - if unknown
    

提交回复
热议问题