Back in Bash

Quick little post today,

Using my previous two scripts you’ve (1) been able to separate a massive photo directory into 3rds (2) been able to take one of those directories and identify matching photos and move them into directories of their own, to make it easier to compare the results.

Now you’ve got a bunch of directories, most of which have 1 photo in them… what do you do.

I decided to take a break from Python for this one, it just didn’t seem the appropriate hammer for this nail.

So here’s a bit of bashing for you, I have an itch somewhere that makes me believe you can stat a directory to determine how many files are in it, but in this case find is the cheap date I was looking for.

After this script, which I call consolidate.sh, you’ll be left with only the directories which have duplicates, Enjoy!


#!/bin/bash

for e in `ls`; do
if [ -d $e ]; then
total_files=$(find $e -type f | wc -l)
if [ $total_files -le 1 ]; then
find $e -type f -exec mv {} !/uniques \;
rmdir $e
fi
fi
done

About jay

I'm trying to build something interactive where I can learn from others and hopefully share useful knowledge too. thecapacity@gmail.com
This entry was posted in code, opensource. Bookmark the permalink.

One Response to Back in Bash

  1. jay says:

    Incidentally, I realize the syntax is jacked up… I’m looking for a plugin to fix this.

Comments are closed.