Skip to content

Instantly share code, notes, and snippets.

@Colorfulstan
Last active June 16, 2016 09:12
Show Gist options
  • Save Colorfulstan/52a75df8aeed4379d41d5386a088e86a to your computer and use it in GitHub Desktop.
Save Colorfulstan/52a75df8aeed4379d41d5386a088e86a to your computer and use it in GitHub Desktop.
Create tar for logs (or files in general) with previous month in filename on Ubuntu / Linux / Unix And delete those files afterwards
DATESTAMP="$(date -d "1 month ago" +"%Y-%m")"
FILESPEC="*${DATESTAMP}*.log"
tar cvzf "${DATESTAMP}.tar.gz" $FILESPEC && rm ${FILESPEC}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment