Skip to content

Instantly share code, notes, and snippets.

@skurscheid
Created June 13, 2020 03:36
Show Gist options
  • Save skurscheid/b3917e666ed608b47d4c28021494f272 to your computer and use it in GitHub Desktop.
Save skurscheid/b3917e666ed608b47d4c28021494f272 to your computer and use it in GitHub Desktop.
Bash function to generate TAR file of a directory with MD5 checksums of included fly; can be used in conjunction with ls | xargs -n1 -I% bash -c 'tar_md5 "$*"' _ % to loop over directory contents
#!/bin/bash
function tar_md5 {
DIR=${1}
if [[ -d $DIR ]]
then
tar -cvpf ${DIR}.tar ${DIR}/| xargs -I '{}' sh -c "test -f '{}' && md5sum '{}'" | tee ${DIR}.md5
fi
}
export -f tar_md5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment