Skip to content

Instantly share code, notes, and snippets.

@XavierMarchena
Forked from moiseevigor/xstat
Last active April 25, 2018 13:55
Show Gist options
  • Save XavierMarchena/2344c3304f49a0643dac9575a6c7893f to your computer and use it in GitHub Desktop.
Save XavierMarchena/2344c3304f49a0643dac9575a6c7893f to your computer and use it in GitHub Desktop.
xstat bash function to get file creation time on Linux with EXT4
#utility http://moiseevigor.github.io/software/2015/01/30/get-file-creation-time-on-linux-with-ext4/
xstat() {
#temporary file to be sorted
temp_file=$(mktemp)
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}" >> $temp_file
done
sort -k1 -k2M -k3 -k4 -k5 -k6 $temp_file
rm ${temp_file}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment