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

后端 未结 12 1749
有刺的猬
有刺的猬 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:40

    Cited from https://unix.stackexchange.com/questions/50177/birth-is-empty-on-ext4/131347#131347 , the following shellscript would work to get creation time:

    get_crtime() {
       for target in "${@}"; do
           inode=$(stat -c %i "${target}")
           fs=$(df "${target}"  | tail -1 | awk '{print $1}')
           crtime=$(sudo debugfs -R 'stat <'"${inode}"'>' "${fs}" 2>/dev/null | grep -oP 'crtime.*--\s*\K.*')
           printf "%s\t%s\n" "${target}" "${crtime}"
       done
    }
    

提交回复
热议问题