Skip to content

Instantly share code, notes, and snippets.

@moiseevigor
Last active October 12, 2022 06:32
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save moiseevigor/8c496f632137605b322e to your computer and use it in GitHub Desktop.
Save moiseevigor/8c496f632137605b322e to your computer and use it in GitHub Desktop.
xstat bash function to get file creation time on Linux with EXT4
xstat() {
for target in "${@}"; do
inode=$(ls -di "${target}" | cut -d ' ' -f 1)
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" "${crtime}" "${target}"
done
}
@nehaljwani
Copy link

Requires sudo :'(

@JulioJu
Copy link

JulioJu commented Aug 25, 2016

@nehaljwani On Arch Linux, not requieres sudo !
@moiseevigor Thinks for your utility !!! Have you an idea how to preserve 'crtime' during copy ? I've looked for on internet, but I've found nothing. I think, we need a tool for change 'crtime'. If there is this tool, we can update crtime of new file with crtime of original file.

Thinks in advance !!

@tony-austin
Copy link

Suggest changing line twenty to fs=$(df "${target}" | awk '/^[^Filesystem]/ && /^\// {print $1}' ), this gets around the issue of DF's handling of long path names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment