 <p>Something to get you stared, adapt to your own needs:</p> <p>Lets create some files:</p> <pre><code>$ touch a-b-2013-02-12-16-38-54-{a..f}.png $ ls a-b-2013-02-12-16-38-54-a.png a-b-2013-02-12-16-38-54-c.png a-b-2013-02-12-16-38-54-e.png f.py a-b-2013-02-12-16-38-54-b.png a-b-2013-02-12-16-38-54-d.png a-b-2013-02-12-16-38-54-f.png </code></pre> <p>Some python</p> <pre><code>#!/usr/bin/env python import glob, os files = glob.glob('*.png') for f in files: # get the character before the dot d = f.split('-')[-1][0] #create directory try: os.mkdir(d) except OSError as e: print 'unable to creade dir', d, e #move file try: os.rename(f, os.path.join(d, f)) except OSError as e: print 'unable to move file', f, e </code></pre> <p>Lets run it</p> <pre><code>$ ./f.py $ ls -R .: a b c d e f f.py ./a: a-b-2013-02-12-16-38-54-a.png ./b: a-b-2013-02-12-16-38-54-b.png ./c: a-b-2013-02-12-16-38-54-c.png ./d: a-b-2013-02-12-16-38-54-d.png ./e: a-b-2013-02-12-16-38-54-e.png ./f: a-b-2013-02-12-16-38-54-f.png </code></pre>