Skip to content

Instantly share code, notes, and snippets.

@ObjSal
Created August 10, 2016 03:35
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 ObjSal/abbf04b679348d18156d86401ee06db2 to your computer and use it in GitHub Desktop.
Save ObjSal/abbf04b679348d18156d86401ee06db2 to your computer and use it in GitHub Desktop.
This script moves all mp3 files in a folder to different directories containing 255 files each, I used this script because one of my Dad's vehicle can only hols 255 per folder and he had 1,000+ songs in a USB drive
#!/bin/bash
# The first folder moves only 253 files, but that's ok for my use =)
folder_count=1
file_count=1
pushd /Volumes/NO\ NAME/
mkdir ${folder_count}
for f in *.mp3; do
file_count=$(($file_count + 1))
if [ $(($file_count % 255)) == 0 ]; then
folder_count=$(($folder_count + 1))
mkdir ${folder_count}
fi
mv "${f}" "${folder_count}/"
done
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment