When exporting from Photos.app with settings that preserve the album & folder structure, every album folder contains dated folders for every date represented in that album, with the actual images inside those. An example export for this question gives this structure…
Export/
Colour/
11 November 2005/
img_0440.jpg
13 November 2005/
pb130006_1_1.jpg
Life/
Creatures/
12 November 2005/
img_0453.jpg
People/
9 November 2005/
img_0174.jpg
10 November 2005/
img_0181.jpg
14 November 2005/
pb140009.jpg
Plants/
10 November 2005/
img_0404.jpg
img_0408.jpg
13 November 2005/
img_0477.jpg
14 November 2005/
img_0625.jpg
What can I run in Terminal to traverse the contents of Export & move all found files up one directory level?
The desired result on my example would be…
Export/
Colour/
img_0440.jpg
pb130006_1_1.jpg
Life/
Creatures/
img_0453.jpg
People/
img_0174.jpg
img_0181.jpg
pb140009.jpg
Plants/
img_0404.jpg
img_0408.jpg
img_0477.jpg
img_0625.jpg
A solution that works in bash
, because I do a lot of my CL stuff in BBEdit which is bash
only, or fish
because that's my preferred shell in Terminal, would be preferred, but I'll work with other shells.
Best Answer
This is untested: remove the
echo
if it looks right:The odd-looking trailing
sh
is required because it gets set as$0
in the shell body, so the rest of the arguments fed to it by xargs can be easily iterated.This will leave the empty directories. To list empty directories:
To delete empty directories:
To not rely on the file extension: