Created
December 6, 2017 13:23
-
-
Save jlinoff/ca0e5a2187e86abdf4b7802707df2250 to your computer and use it in GitHub Desktop.
Bash script to purge all but the last N files that match a pattern.
This file contains hidden or 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 | |
# | |
# Purge all but the last N files in the input list. | |
# | |
if (( $# > 1 )) ; then | |
readonly NUM=$1 | |
shift | |
readonly LIST=($*) | |
readonly LEN=$(( ${#LIST[@]} - $NUM )) | |
if (( LEN )) ; then | |
echo "purging ${LIST[@]:0:$LEN}" | |
rm -rf "${LIST[@]:0:$LEN}" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment