新闻详情

新闻详情

首页 / 资讯中心 / 详情

Get File Creation Date/Time in Bash

发布时间:2026/9/3 17:23:07来源:尧图网络
Get File Creation Date/Time in Bash
1. OverviewIn this tutorial, we’ll learn various methods to get the file creation date on Linux systems.2. Why Can’t We Get the Creation Date on Old Systems?Older systems run old versions of filesystems, which don’t store the file creation date.As the POSIX standard only specifies three types of timestamps to be stored for a file, there is no requirement for a filesystem to support anything beyond them. These three timestamps store information about:Last data access –atimeLast data modification –mtimeFile status changes –ctimeHowever, newer filesystems such asext4,zfs,btrfs,JFS,andXFSdo store the creation timestamp in separate fields:ext4 –crtimezfs –crtimeXFS –crtimebtrfs –otimeJFS –di_otimeThese fields point to data stored in file inodes.3. Getting the File Creation Date UsingstatThe easiest way to get the file creation date is with the stat command.Let’s create a file and check its creation time:$ date; echo Hello file Fri Dec 17 11:26:25 IST 2021 $ cat file Hello $ stat file File: file Size: 6 Blocks: 8 IO Block: 4096 regular file Device: 19h/25d Inode: 1451722 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1000/baeldung) Gid: ( 1000/baeldung) Access: 2021-12-17 11:26:25.578441510 0530 Modify: 2021-12-17 11:26:25.578441510 0530 Change: 2021-12-17 11:26:25.578441510 0530 Birth: 2021-12-17 11:26:25.578441510 0530CopyAs we can see, the creation date is shown in the “Birth” field.Now, let’s modify the file and check that only the “Modify” field changes, as it indicates the last modification time:$ echo Modified file $ cat file Hello Modified $ stat file File: file Size: 15 Blocks: 8 IO Block: 4096 regular file Device: 19h/25d Inode: 1451722 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1000/baeldung) Gid: ( 1000/baeldung) Access: 2021-12-17 11:26:25.578441510 0530 Modify: 2021-12-17 11:28:32.290443553 0530 Change: 2021-12-17 11:28:32.290443553 0530 Birth: 2021-12-17 11:26:25.578441510 0530CopyWe can also instructstatonly to give us the required data, which is the file creation date in our case.For this, we can use the–formatflag with%was its value:$ stat -c %w file 2021-12-17 11:26:25.578441510 0530CopyAdditionally, there are many other formats, which can be found withstat –help:$ stat --help ... The valid format sequences for files (without --file-system): ... %U user name of owner %w time of file birth, human-readable; - if unknown %W time of file birth, seconds since Epoch; 0 if unknown %x time of last access, human-readable ...Copy4. Getting the File Creation Date UsingdebugfsWe can also use the debugfs command to find the creation date on ext4 filesystems. However, it is not as intuitive as thestatcommand since its primary purpose is to debug filesystems.Firstly, we need the inode number of our file. We can find it with the ls command.The-iflag makeslsprint the inode numbers of files:$ ls -i ./file 5118705 ./fileCopyWe also need the filesystem of the file. We can find this with the df command:~ $ df ./file Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 26046564 8380600 16338936 34% /CopyNow, we can pass this information to thedebugfscommand.The syntax isdebugfs -R ‘stat inode’ /dev/sdXwhereinodeis our file inode, and/dev/sdXis the filesystem of the file:$ sudo debugfs -R stat 5118705 /dev/sda2 debugfs 1.46.4 (18-Aug-2021) Inode: 5118705 Type: regular Mode: 0644 Flags: 0x80000 Generation: 2975709199 Version: 0x00000000:00000001 User: 1000 Group: 1000 Project: 0 Size: 8 File ACL: 0 Links: 1 Blockcount: 8 Fragment: Address: 0 Number: 0 Size: 0 ctime: 0x61bc31c8:19fee850 -- Fri Dec 17 06:44:24 2021 atime: 0x61bc3224:7f8fe250 -- Fri Dec 17 06:45:56 2021 mtime: 0x61bc31c8:19fee850 -- Fri Dec 17 06:44:24 2021 crtime: 0x61bc2b65:71f8e150 -- Fri Dec 17 06:17:09 2021 Size of extra inode fields: 32 Inode checksum: 0x5ddd5b4b EXTENTS: (0):5279293CopyHere, the creation time is in thecrtimefield mentioned earlier. We can see that we created the file on“Fri Dec 17 06:17:09 2021”.While thectimefield sounds similar tocrtime,it does not tell us the file creation date. It shows us the last time the file status was changed due to modifications such as changing the file permissions.5. ConclusionIn this article, we covered the historical reasons for the unavailability of file creation dates, along with the methods to get the creation date on modern systems.
网站建设高端定制企业官网
RELATED

相关资讯

更多精彩内容,欢迎继续阅读

较早相关资讯

最新相关资讯

基于VOC格式打架数据集的行为检测实战:从YOLOv8训练到部署优化 2026/9/3 18:17:23

基于VOC格式打架数据集的行为检测实战:从YOLOv8训练到部署优化

简介:本资源是一套专为行为识别与目标检测任务构建的打架行为检测数据集,面向计算机视觉初学者、安防算法工程师及YOLO系列模型实践者,解决真实场景中打架行为精准识别与模型训练数据匮乏问题。数据集严格遵循Pascal VOC格式,共62…

阅读更多 →
全球海上风电GIS数据包详解:从MXD、SHP到TIF的实战应用 2026/9/3 18:17:23

全球海上风电GIS数据包详解:从MXD、SHP到TIF的实战应用

简介:本资源为全球海上风电基础设施空间分布权威数据集,面向地理信息、能源规划、环境评估及可再生能源研究领域的科研人员、GIS工程师与政策分析人员,解决海上风机空间位置精准获取、跨国对比分析与制图可视化等核心需求。资源共19个文件&am…

阅读更多 →
企业微信API:企业微信自动运营实践 2026/9/3 18:17:23

企业微信API:企业微信自动运营实践

企业微信自动运营,核心不是单纯“自动发消息”。真正的自动化,是把客户、消息、群聊和业务数据连接起来,让一些重复性的运营工作自动完成。一、企业微信自动运营可以做什么?常见的自动化场景主要有:客户消息自动回复群…

阅读更多 →
圆锥曲线压轴题解析:齐次化与倒角公式的核心应用 2026/9/3 18:17:23

圆锥曲线压轴题解析:齐次化与倒角公式的核心应用

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

阅读更多 →
黑悟空评论数据分析系统:从爬虫到可视化看板完整实现路线 2026/9/3 18:17:23

黑悟空评论数据分析系统:从爬虫到可视化看板完整实现路线

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

阅读更多 →
YOLOv8+PySide6摔倒检测系统实战:从模型训练到桌面应用 2026/9/3 18:14:22

YOLOv8+PySide6摔倒检测系统实战:从模型训练到桌面应用

摔倒检测不是新概念,但真正让它从“一个训练好的模型”变成“一个能打开的桌面软件”,中间隔着一段很多人没走完的路。模型训练好之后,多数人只会用命令行跑一张图片,或者用 model.predict(source0) 开个窗口看结果——然后呢&a…

阅读更多 →

今日资讯

本周资讯

本月资讯

看完文章仍有疑问?

联系尧图顾问,获取一对一建站咨询

立即免费咨询 📞 400-888-8888
📞