My previous answer was began with this wrong statement:
Linux does not store file creation time
Yes - Linux kernel does not provide API to get creation time stamps from file system.
But as it is written in wiki ext4 provide file creation timestamps:
ext4 also adds support for date-created timestamps. But, as Theodore
Ts'o points out, while it is easy to add an extra creation-date field
in the inode (thus technically enabling support for date-created
timestamps in ext4), it is more difficult to modify or add the
necessary system calls, like stat() (which would probably require a
new version) and the various libraries that depend on them (like
glibc).
Also as answered in unix.stackexchange
Several file systems store the file creation time,
although there is no standard name for this field:
- ufs2 → st_birthtime
- zfs → crtime
- ext4 → crtime
- btrfs → otime
- jfs → di_otime
Here is great question/answer how to find file creation stamp. Script written by @terdon:
get_crtime() {
for target in "${@}"; do
inode=$(ls -di "${target}" | cut -d ' ' -f 1)
fs=$(df --output=source "${target}" | tail -1)
crtime=$(sudo debugfs -R 'stat <'"${inode}"'>' "${fs}" 2>/dev/null |
grep -oP 'crtime.*--\s*\K.*')
printf "%s\t%s\n" "${target}" "${crtime}"
done
}
Add this script to your .bashrc.
Now using this script you can get what you want.
Go to folder which content you want to sort
$ cd ~/Downloads
$ get_crtime * | sed -r 's/\s+/ /g' | cut -d" " -f1,3,4,6 | sort -k2M -k3,4n
For tar.gz
files
$ get_crtime *.tar.gz | sed -r 's/\s+/ /g' | cut -d" " -f1,3,4,6 | sort -k2M -k3,4n
Sources
Best Answer
There is a way to know the creation date of a directory , just follow these steps :
Know the inode of the directory by
ls -i
command (lets say for example its X)Know on which partition your directory is saved by
df -T /path
command ( lets say its on/dev/sda1
)Now use this command :
sudo debugfs -R 'stat <X>' /dev/sda1
You will see in the output :
crtime is the creation date of your file .
What I tested :
Modified it by creating a file .
I tried the command and it gave an exact time .