Skip to content

Instantly share code, notes, and snippets.

@catichenor
Created August 3, 2018 16:44
Show Gist options
  • Save catichenor/f53ab49a53616ec5412ef8d3cf430742 to your computer and use it in GitHub Desktop.
Save catichenor/f53ab49a53616ec5412ef8d3cf430742 to your computer and use it in GitHub Desktop.
Get the modification date of files inside zip archives in the current directory
#!/bin/bash
for f in `find -maxdepth 1 . -type f -name '*.zip'`; do
datetime=`date -j -f "%y-%b-%d %H:%M" "$(zipinfo $f | head -n 3 | tail -n 1 | awk '{print $7 " " $8}')" +"%Y%m%d%H%M"`;
echo "$f $datetime"
# To rename, appending the date instead: mv $i `echo "$i" | sed -e "s/\(.*\)\(\..*\)/\1_${datetime}\2/"`;
done
@catichenor
Copy link
Author

Note that I'm using BSD date, not GNU date to parse the date that's output from zipinfo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment