?

Log in

No account? Create an account
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
unixish
[yaarg]
[Tags|]

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!
LinkReply

Comments:
From: (Anonymous)
2006-09-01 08:35 am (UTC)

Pipelining

Here's a pipelining approach.

find . -maxdepth 1 -type f -print0 | xargs -0 stat -c '%y!%n' | sed 's/^\(....-..-..\)[^!]*!\(.*\)/\1\n\2/'|tr '\n' '\0'|xargs -0 -n 2 sh -c 'mkdir -p "$0" && mv "$1" "$0/"'

I don't like the sh -c hack, and would rather simply construct the commands entirely in the sed expression, and then eval them, but I don't know how to do that without another sh -c hack... Point-free programming is cool. (Or was it pointless? :)

--tuomov
(Reply) (Thread)