Skip to content

Instantly share code, notes, and snippets.

@RavinduSachintha
Created March 27, 2022 04:13
Show Gist options
  • Save RavinduSachintha/029fdc9bf5c97dfa699e4c3214598427 to your computer and use it in GitHub Desktop.
Save RavinduSachintha/029fdc9bf5c97dfa699e4c3214598427 to your computer and use it in GitHub Desktop.
This shell script will create folders for files inside the current folder and move those files to their respective folders. Shell scripts are excluded. I usually use this for sorting movies and other videos in my machine.
#!/bin/bash
process() {
folderName="$(basename "$1" | sed 's/\(.*\)\..*/\1/' | sed 's/ /_/g')"
mkdir -p $folderName
mv "$(basename "$1")" $folderName
}
export -f process
find . -maxdepth 1 -type f -not -name "*.sh" -exec bash -c 'process "$0"' {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment