Skip to content

Instantly share code, notes, and snippets.

@arnabdas
Last active May 20, 2017 05:28
Show Gist options
  • Save arnabdas/b60ba4fdc762b8e805505fce5d4d6c36 to your computer and use it in GitHub Desktop.
Save arnabdas/b60ba4fdc762b8e805505fce5d4d6c36 to your computer and use it in GitHub Desktop.
Split all the files into intended sizes inside a folder with 7zip
#! /bin/bash
# a - add to archive
# -mx0 - copy only
# -v250m - makes split of 250 MB of each files
#7z a <new_name>.7z -mx0 -v250m <intermediate_name>.7z
# set the minimum size in bytes (here: 100mb)
minimumSize=100000000
for i in *.7z; do
# get actual size of the files
actualSize="$(wc -c <"$i")"
if [ "$actualSize" -gt "$minimumSize" ]
then
# get the file name without the extension
fileName="${i%.*}"
# create a directory as the same name of the file
mkdir "$fileName"
# move the large file to the directory
mv "$i" "$fileName"
# change to the directory
cd "$fileName"
# make the large file intermediate
changedFileName="_$i"
mv "$i" "$changedFileName"
# split the files into 100mb parts
7z a "$i" -mx0 -v100m "$changedFileName"
# delete the intermediate file
rm -f "$changedFileName"
# restore the directory
cd ..
else
echo "$i is less than 100mb"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment