Last active
October 12, 2022 06:32
-
-
Save moiseevigor/8c496f632137605b322e to your computer and use it in GitHub Desktop.
xstat bash function to get file creation time on Linux with EXT4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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 !!
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
Requires sudo :'(