List file creation date in bash

Click For Summary

Discussion Overview

The discussion revolves around how to list the creation date of files in Linux bash, specifically focusing on the differences in functionality across various file systems and versions of core utilities. Participants explore various commands and their applicability, as well as the limitations imposed by different environments.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Exploratory

Main Points Raised

  • One participant inquires about listing the creation date of files, emphasizing the need for this information beyond just modification dates.
  • Another participant cites 'man ls' on Mac OS, stating that 'ls -Ul' can show file-creation times, but this does not apply to GNU bash on Red Hat Linux.
  • A participant explains that the ability to retrieve file creation times depends on the file system, listing several file systems that support creation times, such as ext4 and btrfs, and suggesting the use of the 'stat' command.
  • One user reports that their file system is ext3 and that their version of 'stat' lacks options to show creation times, prompting a request for further guidance.
  • Another participant suggests installing ext4 support and the latest coreutils to enable creation time retrieval, while also questioning the user's intent without using the term "creation date."
  • A participant expresses reluctance to undertake extensive changes and seeks clarification on how to determine when content was initially created.
  • One user proposes that 'ctime' could serve as a substitute for creation time, explaining its relationship to file changes.
  • Another participant challenges the reliability of 'ctime' for determining creation time, noting discrepancies in file timestamps.
  • A later reply suggests checking if the file manager can display creation times, indicating that if it is available, there may be a way to retrieve it through other means.
  • One participant reiterates that while 'ctime' might approximate creation time, it does not guarantee accuracy and lacks a definitive method to confirm it.

Areas of Agreement / Disagreement

Participants express differing views on the availability and reliability of file creation dates across various systems and commands. There is no consensus on a definitive method to retrieve file creation dates in all scenarios.

Contextual Notes

Limitations include the dependency on specific file systems and versions of core utilities, as well as the lack of support for certain commands in different environments.

nvn
Science Advisor
Homework Helper
Messages
2,128
Reaction score
32
How do you list creation date of a file in linux bash? I want to find creation date of some files, not just modification date. Thanks.
 
Technology news on Phys.org
According to 'man ls' on Mac OS, 'ls -Ul' shows the file-creation time instead of the last-modification time, in the long-format output.
 
That does not appear to work on GNU bash; i.e., "ls -Ul" does not appear to give file creation date on GNU bash (redhat linux). Any other ideas?
 
Last edited:
It depends on the file system. Traditionally UNIX file systems like ffs, ufs, and ext2 only kept mtime, ctime and atime: mtime == modifocation time, ctime == inode change time, and atime == access time.

Some newer filesystems have file creation times:
ufs2 → st_birthtime
zfs → crtime
ext4 → crtime
btrfs → otime
jfs → di_otime

Code:
stat -c %W filename
stat -c %w filename
Is one way to show it. Since ls is part of coreutils you have to have an ext4 filesystem (for example) mounted with the correct options and you need a recent version coreutils.

If your ls man page does not show an option then you are stuck with stat, which had crtime support earlier.

This is not an "idea" - this is how the thing works. Check
Code:
mount -p
to see what filesystems you have.

Code:
/etc/mnttab
lists exactly all mount options, filesystems, etc. Harder to read. This is a file so user the less command.
 
Last edited:
The mount command appears to say the file system is "ext3 (rw,nodev)." My stat command does not have a %W nor %w option. If I issue only the command "stat filename," it lists the following. What should I try now?

Access: <date/time>
Modify: <date/time>
Change: <date/time>​
 
Last edited:
Um. the polite term is you are out of luck.

An answer that is constructive but probably NOT what you want to hear:
1 download the package, rpm or whatever your linux calls it, for ext4 support.
2. install ext4.
3. mount the ext4 filesystem. Follow the guidelines for enabling crtime support.
4. All files written onto the new filesystem will then have creation dates.
Next.
1. download and install the very latest coreutils for your linux. Your commands now support creation times.

Don't do all that unless you are really masochistic.

Without using the word creation date (or time) please tell me what you are actually trying to do. Where there is a shell there is a way.
 
I am not that masochistic. :biggrin:

Because I want to know when some content was initially created, I do not know how to explain it without using some of the words in post 1. Anyway, thank you very much for the help.
 
ctime will do for most of what creation time does.

Unless you use these commands a lot: chmod, chown, setfacl
ctime is completely identical to creation time as kept by windows.

Code:
cd /path/to/content
ls -ltc *.whatever  # files in order most recent -> oldest and shows ctime
ls -ltrc *.something  # files in order oldest -> most recent and shows ctime

Based on your questions I would guess that chmod, chown, and setfacl are not a standard part of your everyday linux usage, so chances are really good this will do what you want.
 
No, "ls -ltc" shows, e.g., "2012-11-04" on almost all of my files, or a large percentage of them, even though I did not change anything in or about those files in that time frame. Therefore, that command is not working for giving me any indication of file creation date. But thanks again for all the information.
 
  • #10
Quick question...

forget about GNU bash for a moment...can you get creation time for your files any other way?

just trying to figure out if it is even being preserved by your OS or available with your FS

can you see creation time using the file manager? (nautilus? or whatever?)

if it is available, then, I am sure there is a way to retrieve it...in the worst case, you may need to figure out what the file manager is doing to get it.

any way, just checking, just a thought
 
  • #11
jim mcnamara said:
ctime will do for most of what creation time does.

ctime gives the time when the inode (i.e. the directory entry that points to the file) was last changed. mtime gives the time when the file was last changed.

ctime MIGHT be the time when the file was first created, but there is no guarantee, and no way to find out if it is or isn't AFAIK.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 10 ·
Replies
10
Views
2K
Replies
35
Views
8K
Replies
4
Views
3K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
3
Views
3K
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K