BASH script to remove numeric prefix from files downloaded from scribd

Scribd is a great service, offering PDF downloads of a variety of content.  Unfortunately there is an ugly 8 digit (random?) number prefixed on each file downloaded.

47432750-Book-Name-Whatever.pdf
47501680-Another-Book-Name.pdf
47502885-Yet-Another-Book-Name.pdf

It’s not descriptive, and it makes alphabetic sorting of the files downloaded impossible.  Here’s a small BASH shell script that will remove the first 9 characters (8 digits and the – character) from all pdf files in a directory.

#!/bin/bash
for f in *.pdf; do
file=${f:9}
[ ! -f $file ] && mv "$f" $file
done

Create the above in a file, save it, and be sure to use chmod +x filename to make the shell script executable.

About Timothy Platt

I'm an all around computer junkie, interested in many aspects of programming, operating systems, and enterprise IT technologies. I love Mac OS X, Linux, and Windows and I'm not particularly militant about any one over the other.
This entry was posted in Mac OS X. Bookmark the permalink.

Comments are closed.