mac

Random Rename file with md5 Hash [Scripts]

Sometimes I find it handy to randomly rename files with md5 hashes. Don't you ever feel like you need to do that? This script involves a line of PHP so to use it make sure you have PHP installed on your system.

It accepts either a file or a wildcard glob such as '*.jpg' (no quotes).

#!/bin/bash

while [ $# -gt 0 ]
do
	if [ -f "${1}" ]; then
		sz_basename=`basename "${1}"`
		sz_dirname=`dirname "${1}"`
		NEW_FILE=`php -r "echo md5('$sz_basename'.mt_rand());"`.${sz_basename#*.}
		echo "$1 => ${sz_dirname}/${NEW_FILE}"
		mv "$1" ${sz_dirname}/${NEW_FILE}
	fi
	shift
done

bz2 Compress a Folder [Scripts]

I use a ton of bash scripts when I'm working at my Mac or at a Linux workstation. It's time to document these things.

This is a real simple one. It expects a single parameter and it expects that parameter to be a folder name that you'd like to bz2 compress. The tar.bz2 compressed folder is written to the same parent directory as the folder you pass as a parameter.

#!/bin/bash

if [ -d "$1" ]; then
	tar -cjf "${1}.tar.bz2" "$1"
else
	echo "error: expected directory as first parameter"
	echo "useage: $ dirtobz2 path/to/folder"
fi
Syndicate content