diff --git a/src/tagfarm/main.py b/src/tagfarm/main.py
index 7258c7a..544507b 100644
--- a/src/tagfarm/main.py
+++ b/src/tagfarm/main.py
@@ -64,12 +64,12 @@
     index = index_files(media_root)
 
     by_tags_dir = os.path.join(media_root, 'by-tag')
-    for tag in os.listdir(by_tags_dir):
+    for tag in sorted(os.listdir(by_tags_dir)):
         tagdir = os.path.join(by_tags_dir, tag)
         if not os.path.isdir(tagdir):
             continue
         print('*** {}'.format(tag))
-        for basename in os.listdir(tagdir):
+        for basename in sorted(os.listdir(tagdir)):
 
             linkname = os.path.join(tagdir, basename)
 
@@ -197,7 +197,7 @@
     dest_basename = os.path.basename(dest)
 
     by_tags_dir = os.path.join(media_root, 'by-tag')
-    for tag in os.listdir(by_tags_dir):
+    for tag in sorted(os.listdir(by_tags_dir)):
         old_linkname = os.path.join(by_tags_dir, tag, src_basename)
         if os.path.lexists(old_linkname):
             os.remove(old_linkname)
@@ -225,7 +225,7 @@
     dest = os.path.normpath(options.dest)
     mkdir_p(dest)
 
-    for basename in os.listdir(tagdir):
+    for basename in sorted(os.listdir(tagdir)):
         linkname = os.path.join(tagdir, basename)
 
         filename = os.path.join(tagdir, os.readlink(linkname))