Using DTerm and the shell to rename files


Posted by Jaime | Posted in Tip | Posted on 06-12-2010

Tags: , , ,

I download files from my bank that have some really long name to them and at the end of the name, is the date.

The date is not formatted, of course, and I wanted to rename the files easily, without manually parsing out the string.

Now on my computer, I have DTerm and TextMate at my disposal. So, I created a shell script that would take two parameters: the path to the file and the file name to parse:

#!/usr/bin/env bash
echo "Starting script with parameters $1 $2"
cd $full_path
mv $file_name "${year}-${month}-${day}_statement.PDF"

Now that I saved the script in my Documents folder, I can go to where my file is downloaded and type:
/Users/jaimerios/Documents/ "$PWD" mysuperlongfilename20101014.PDF

To make things easier, I use TextExpander to type out the command for me in DTerm, then hit “Command+Shift+V” for DTerm to type out the name of the currently selected file.

Then Voila! The file has been renamed!