Skip to content

Instantly share code, notes, and snippets.

@stevekm
Last active September 24, 2015 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevekm/3da96691c4c109e5a38e to your computer and use it in GitHub Desktop.
Save stevekm/3da96691c4c109e5a38e to your computer and use it in GitHub Desktop.
Tar a directory, generate an md5sum, view files, extract contents. Use this over gzip alone.
#!/bin/bash
INPUT_DIR=/path/to/dir/
OUTPUT_FILES=/path/to/output.tar.gz
OUTPUT_DIR=/path/to/
# create a tar.gz from a directory
tar -cvzf $OUTPUT_FILES $INPUT_DIR
# generate a md5sum for the tar.gz
md5sum $OUTPUT_FILES > $OUTPUT_DIR"$(basename $OUTPUT_FILES)"_md5sum.txt
# view contents of the tar.gz
tar -ztvf $OUTPUT_FILES
# exclude some things from the view output; use this to exlclude some dir paths
tar -ztvf $OUTPUT_FILES --exclude '*/*'
# or show only certain lines of the view output
tar -ztvf $OUTPUT_FILES | grep 'pattern'
# extract the tar.gz to a directory
tar -xvzf $OUTPUT_FILES -C /path/to/the/place/where/you/want/the/output/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment