Skip to content

Instantly share code, notes, and snippets.

@emjayoh
Created December 16, 2021 19:31
Show Gist options
  • Save emjayoh/d9dfa3f3c4cb43f6bf6a2218bdf39b44 to your computer and use it in GitHub Desktop.
Save emjayoh/d9dfa3f3c4cb43f6bf6a2218bdf39b44 to your computer and use it in GitHub Desktop.
[move sub^2 dir to parent dir] #bash
#!/bin/bash
#needed in case we have empty folders
shopt -s nullglob
#we must write the full path here (no ~ character)
target="/path/to/photos"
#we use a glob to list the folders. parsing the output of ls is baaaaaaaddd !!!!
#for every folder in our photo folder ...
for dir in "$target"/*/ do
#we list the subdirectories ...
for sub in "$dir"/*/ do
#and we move the content of the subdirectories to the parent
mv "$sub"/* "$dir"
#if you want to remove subdirectories once the copy is done, uncoment the next line
#rm -r "$sub"
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment