Skip to content

Instantly share code, notes, and snippets.

@ashayh
Created January 19, 2013 01:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ashayh/4570187 to your computer and use it in GitHub Desktop.
Save ashayh/4570187 to your computer and use it in GitHub Desktop.
Extract ext4 creation (crtime) of file
#!/bin/bash
# Author: ashay dot humane at gmail.com
# Given a file name, this script prints the file creation time,
# as ext4 records it
# Might error out on other filesystems
DEBUGFS="/sbin/debugfs"
[[ -f "$1" ]] || { echo "Invalid filename. Exiting" ; exit 1; }
[[ -f "$DEBUGFS" ]] || { echo "/sbin/debugfs absent. Exiting" ; exit 1; }
[[ $EUID != 0 ]] && { echo "You are not root. Exiting" ; exit 1 ; }
INODE=$(ls -i "$1" |cut -d' ' -f1)
DEV=$(df "$1" | awk 'NR == 2 {print $1}')
CMD="${DEBUGFS} -R \"stat <${INODE}>\" ${DEV} 2>/dev/null"
echo running: ${CMD}
echo
eval ${CMD} | grep "crtime"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment