r/scripting • u/swardshot • Mar 08 '19
Looking for help creating a bash script that will move all files of a certain type into folders in multiple subdirectories.
I’m working to move all .JPG and .MOV files into specific folders JPEGs and Videos on each day. Currently all of my files are in a directory structure as follows...
{year}/{year-month}/{year-month-day}/ 2019/2019-03/2019-03-08/
This is my folder structure going back 7 years now. I figured out how to create a directory in each day folder using...
for dir in */; do mkdir — “$dir”/{JPEGs,Videos}; done
This creates the folders where I need them for each month but I’m lost on how I can script moving the .JPG files and .MOV files to the correct folders in each day. I can go into each folder and run mv *.JPG JPEGs/ but there must be a way to automate this?
Thanks!
UPDATE: thank you all who took the time to comment, I am not pursuing this folder structure as it does not fit into my photography workflows as I originally intended. If you do have a solution and want to share it for everyone’s knowledge, feel free to share!
4
u/Kaligraphic Mar 08 '19 edited Mar 08 '19
How are you assigning dates to the files?
If this is just “all files from today, and clear out the directory for tomorrow”, you’ll probably want to look at and understand:
Date
Find . -t file -iname ‘*.mov’ -exec mv -t $WEIRDLY_DETAILED_PORN_LOG_PATH/Videos {} +
Proper understanding of find is quite helpful in bash or other shells.
2
u/Lee_Dailey Mar 08 '19
howdy swardshot,
i've no knowledge of bash, so this is just my curiosity ...
why are you using such a convoluted dir structure? my date-filed items are in
YearNumber\MonthNumber\DayNumber. your layout seems repetitively repetitious ... [grin]take care,
lee
1
u/wast3dLuci0 Mar 08 '19
You can automate the mv command with Crontab if you are using Linux. You can set it up to do it once a week or a day or whatever