Skip to content

Instantly share code, notes, and snippets.

@madduci
Last active September 17, 2019 20:20
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 madduci/3934e2c927f1eadb61e411be457e9834 to your computer and use it in GitHub Desktop.
Save madduci/3934e2c927f1eadb61e411be457e9834 to your computer and use it in GitHub Desktop.
Sorting files in folders
#!/bin/bash
readonly INPUT_FOLDER="${1}"
cd ${INPUT_FOLDER}
find . -type f -print0 | while read -d $'\0' file
do
information=$(ls -lt --time-style=+%b-%Y "${file}")
filedate=$(echo "${information}" | awk '{print $6}')
filename=$(echo "${information}" | awk '{print $7}' )
destination_folder="${INPUT_FOLDER}/${filedate}"
mkdir -p "${destination_folder}"
printf "Moving %s in %s\n" "${filename}" "${destination_folder}"
mv "${file}" "${destination_folder}/"
done
cd -
echo "Sorting completed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment