Scala code to find (and move or remove) duplicate files

My MacBook recently told me I was running out of disk space. I knew that the way I was backing up my iPhone was resulting in me having multiple copies of photos and videos, so I finally decided to fix that problem by getting rid of all of the duplicate copies of those files.

So I wrote a little Scala program to find all the duplicates and move them to another location, where I could check them before deleting them. The short story is that I started with over 28,000 photos and videos, and the code shown below helped me find nearly 5,000 duplicate photos and videos under my ~/Pictures directory that were taking up over 18GB of storage space. (Put another way, deleting those files saved me 18GB of storage.)

Unix find command: How to move a group of files into the current directory

I just bought a bunch of MP3 music files from Amazon, and when I downloaded the zip file they provide onto my Mac, it was a bunch of files in a bunch of subdirectories; not really convenient to work with when you’re trying to import them into iTunes. So I used this Unix find command to move all of the music files from the subdirectories they were scattered in into the root directory that was created when I expanded the zip file:

cd Amazon-Music-Folder
find . -type f -exec mv {} . \;

If you ever need to either copy or move a bunch of files with a single command, I hope this example shows the correct find command syntax for your needs. (If you need to copy the files, use the cp command instead of the mv command.)

Ten years since the move to Alaska

It’s hard to believe it’s been this long, but ten years ago today I hopped in the car, aimed in the general direction of Alaska, and a little less than a month later I ended up in Talkeetna. Hopefully in another ten years The Squirrel and I will be sitting on the front porch again, eating popcorn, Cheerios, cherries, and PB&J sandwiches, and catching up on the last twenty years of adventures.

A Unix find and move command (find in subdirectories)

This is a dangerous Unix command, but if you want to move a bunch of files from their subdirectories into your current directory, this find and mv command works:

find . -type f -exec mv {} . \;

That command finds all files beneath the current directory, and moves them into the current directory. I just moved a bunch of files from their (iTunes) subdirectories into my current working directory, and that find and move command did the trick. (But again, it’s a dangerous command, be careful out there.)