Backup your files before you try this. It could be destructive...
Part of the problem is using for
when iterating through folders with some spaces in their names. You'll end up with an inconsistent list because whitespace and carriage returns are both field separators. You need to set IFS
to a carriage return only. (You can use find -exec
to work on filesystem entries directly, but that gets messy when working with nested wildcards)
This should do the job, but be warned that moved files will overwrite matching ones in the destination folders. Run it from the root folder of the above.
# Set IFS to carriage return only.
IFS='
'
# Find all the matching folders and move the .jpg files out of them to the sibling folder.
for a in $(find . -type d -name *#*); do b=${a::-3}; mv $a/*.jpg $b/; rmdir $a; done
A few assumptions made:
- that the structure you've described is year/month/day subfolders. (If the folder names contain \
it gets uglier)
- that you you just have some folders with a #2
suffix
- that you want to remove the #2 folders once you've moved the files out.
See here for how to do more weird things with strings in bash...