Created
July 18, 2018 05:12
-
-
Save tony-johnson/996ec02b59e4d67859f4d187ad7c7ea4 to your computer and use it in GitHub Desktop.
Example file for compressing .fits files while maintaining modification date and file name
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
#!/bin/bash | |
# Compress a FITS file while preserving its name and date | |
# | |
# Can be used as follows: | |
# | |
# find . -name "*.fits" -mtime +30 -exec fcompress {} \; | |
# | |
# Note that fpack will not recompress file already compressed, | |
# maybe that is good enough, but we also set a file attribute | |
# in case we need to test that in future for efficiency reasons. | |
set -e # Exit on error | |
tstamp=`date -r $1 +%Y%m%d%H%M.%S` | |
before=`stat -c%s $1` | |
fpack -F -g2 $1 | |
attr -q -s user.fpack -V true $1 | |
touch -t $tstamp $1 | |
after=`stat -c%s $1` | |
if (($after < $before)); then | |
compression=`echo "scale=2; 100*$after/$before" | bc` | |
echo $1 $compression% | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment