Thursday, June 30, 2016

lscrtime -- Get crtime ext4 Creation Timestamp

 Get the creation time, from ext4 using debugfs. To use just enter a regex that matches the files/directories in the cwd that you want to display. If you have multiple files with the same extension yet only want one, simply complete the regex with a $.
E.g. If these files are in the cwd: file_1 file_10 file_10000
  To get the creation time of file10:
   $> lscrtime file_10$
 To list the creation time of all three:
   $> lscrtime file_1 (if no other files are in the directory)
      -- or -- (more specifically)
   $> lscrtime 'file_1[0]{0,5}$'
alias lscrtime='_() { local fs="";while IFS=" " read -d "" a b; do fs=$(df "${b:-.}"|tail -1|sed "s/ .*$//");crtime="$(sudo debugfs -R "stat <${a}>" "${fs}" 2>"${DISCARD_DEV}"|grep crtime|sed "s/.*-- //")"; echo "${b} ${crtime}"; done < <(find . -maxdepth 1 -regextype posix-extended -regex "^(./)*${1}.*" -printf "%i %f\0");};_' 

Saturday, June 18, 2016

Removing Duplicate Files

#!/usr/bin/env bash 

old_var="zzz"
var="xxx"
[ -n "${1}" ] && CMD="echo Dryrun: "
while read a; do 
var="$(basename "${a}")"
[ "${var}" == "${old_var}" ] && ${CMD} rm -v "${a}" || old_var="${var}"
done < <(find . -type f | rev | sort -t'/' -k 1 | rev) 
Note: This uses names only, to make it robust add md5sums.