Handbrake batch conversion using CLI shell script

I contributed to a Handbrake forum a while back. Thought you might find it useful too.

This is my evolving script for transcoding DVDs from MacTheRipper.

1) Save the file in a logical place (I keep it in the Movies Folder… same place I rip movies to). It will loop through all titles longer than X.

# usage is ./thisScript.sh minimumDuration SomeDirContainingVIDEO_TS
# duration is set in minutes ("30" equals 30 minutes)
# specify the container directory for the VIDEO_TS directory
# example ./handbrake-longer-than.sh 30 24_SEASON6_D1
#set default path to HandBrakeCLI
if [ "${1}x" = "x" ]; then
echo "Minutes not provided"
if [ "${2}x" = "x" ]; then
echo "VIDEO_TS path not provided"
export time
for i in $(find $2 -type d -name VIDEO_TS) ; do
for title in $($PathToHandBrakeCLI -t 0 -i $i -L 2>&1 | grep "has length" | sed 's/sec//' | sed 's/[()]//g' | awk '$8 > (60 * ENVIRON["time"]) { print $3 "-" $5 } ') ; do
#this names the title for the output file
titlenum=$(echo $title | cut -f 2 -d '-')
# you can change the preset or any other variables here
$PathToHandBrakeCLI -i $i -o ${2}-title${titlenum}-appletv.m4v --preset="AppleTV" -2 -T -P -t ${titlenum}
#output example: 24_SEASON6_D1-title1-appletv.m4v

2) Within the script, set the path to your HandBrakeCLI app on line 9.

3) Don’t forget to run this before trying to execute it:
chmod 777 ./handbrake-longer-than.sh

4) Execute it like this:
./handbrake-longer-than.sh 30 24_SEASON6_D1

Where “30” is the shortest title you want to export and “24_SEASON6_D1” is the name of the folder containing your VIDEO_TS directory.

Hosts File on Mac

I can never remember the path to the hosts file on my MacBook Pro. So, here it is:

sudo nano /private/etc/hosts

Find Large Files in Linux

This doesn’t work perfectly, but I often use it to start tracking down disk hogs:

To return the 10 largest items in a given directory:

du -cksh * |sort -rn |head -11

Some times it’s helpful to view all

du -cksh * |sort -rn

If someone has a better approach, please comment.

Find Failed Login Attempts in Logs

Looking for a log to show you failed login attempts to your Linux machine? Look in:


You can access it by running:


It’s similiar to the wtmp log of user login/logouts and the utmp log showing who is currently logged in.