#!/bin/sh # This bash script, locates unique files using md5sum, # and stores only one instance into another folder that # the user specifies as an argument. usage() { echo "Description:" echo "Identifies unique files by using md5sum " echo "and then copies them into a dirctory." echo echo "Usage: uniqfile [DIR]" echo echo "[DIR] is the path of the directory you " echo "wish to backup your files " echo echo "Command line arguments are not optional." } if [ "$1" = "-h" -o "$1" = "--help" ]; then usage exit 0 elif [ -z "$1" ]; then echo "Invalid arguments." exit 0 else directory=$1 fi echo "Calculating md5..." files=$(md5sum * 2>/dev/null | sort -n | uniq --check-chars=32 | cut -d" " -f3) echo "Copying the files..." cp $files $directory echo "Done." exit