Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Aug 4, 2016

Requires sudo :'(

@JulioJu

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Oct 9, 2016

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
You can’t perform that action at this time.