Skip to content

Instantly share code, notes, and snippets.

@matiskay
Created July 30, 2011 16:31
Show Gist options
  • Save matiskay/1115710 to your computer and use it in GitHub Desktop.
Save matiskay/1115710 to your computer and use it in GitHub Desktop.
Zip files that have the same name
#!/bin/bash
# Reference
# http://stackoverflow.com/questions/965053/extract-filename-and-extension-in-bash
# Description
# If you have these files
# a.x a.y a.z b.x b.y c.z
# The script zip them to
# a.zip b.zip c.zip
function getFilenames() {
for file in $(ls); do
# Get the filename
filename=${file%.*}
echo $filename
done
}
filename=$(getFilenames | uniq)
for x in $filename; do
tar cvfz $x.tar.gz $x.*
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment