Log in

Bob and his many photographs - unixish [entries|archive|friends|userinfo]
Unixish - Solving problems the UNIX way

[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Bob and his many photographs [Sep. 1st, 2006|07:43 am]
Unixish - Solving problems the UNIX way

Okay finally first problem a date later that originally announced.

Problem 1:

Bob finally gave in and went digital a few years ago and since then he's accumulated a vast number of photographs. Sadly each week as he's taken more and more photos and his memory card has filled he's uploaded them to his PC without much thought. As a result Bob finds that his photos directory (~/photos) is now getting out of hand - one thousand files with randomally assigned names. Bob figures that at least having some sort of hierarchy so that the photos were in sub-directories by modified date would be a start.

Can you help Bob out?

Solutions in comments please. Please make sure you put your solution within a <code> or <pre>. Oh yeah and I'm not sure if I should screen the comments at first so other people have a chance to answer? What do people think? I'd like to hear general feedback too!

[User Picture]From: tjernobyl
2006-09-02 12:26 am (UTC)

Here's a quick and messy way to do it.

Figure out what we'll need to do for making directories
ls --time-style=+%Y-%m -l | cut -c 37- | cut -f 1 -d " " | sort | uniq | perl -ne 'print "mkdir $_"' >> cleanup

Figure out how we're gonna be moving the files around
ls --time-style=+%Y-%m -l | cut -c 37- | perl -pe 'chomp; s/(\d\d\d\d\-\d\d) (.+)/mv \"$2\" $1\n/g' >> cleanup

Ok, so now let's do a sanity check to make sure our changes are good
less cleanup

Looks good, let's make it happen.
chmod +x cleanup; ./cleanup

And we have files in directories ordered by month! Huzzah!

This is a really hackish way of doing things; it's dependant on the files in the directory being within a certain size range and other ickies. But as a one-time cleanup, it'll do the trick.
(Reply) (Thread)
(Deleted comment)