diff options
| author | moehm | 2014-05-05 09:28:59 +0200 |
|---|---|---|
| committer | moehm | 2014-05-05 09:28:59 +0200 |
| commit | a4aadb7541c7d9a2453ed6065f40c301e4c0087e (patch) | |
| tree | 13f8248d1f6628e91171c9f79af92b27463b0a77 /bin | |
| parent | c8809f9a5764d24e120f7b64867e733cfaa25b07 (diff) | |
| parent | 15a5425855aecf57a596372f006f4a8412701e54 (diff) | |
| download | dotfiles-a4aadb7541c7d9a2453ed6065f40c301e4c0087e.tar.gz | |
Merge branch 'master' of git.iamfabulous.de:dotfiles
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/duplicate.sh | 70 | ||||
| -rwxr-xr-x | bin/duplicate_size.sh | 13 |
2 files changed, 83 insertions, 0 deletions
diff --git a/bin/duplicate.sh b/bin/duplicate.sh new file mode 100755 index 0000000..655aff2 --- /dev/null +++ b/bin/duplicate.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +# Example usage, find all doubles in all sub directory +# for i in *; do if [ -d $i ]; then double.sh $i; fi; done +# +# To find duplicates in specific directory +# double.sh /path/to/dir /path/to/other/dir ./relativ/path +# +# With zero paramater, the script uses the working diroctory. + +DATABASE="/tmp/double.db" +DIR="./found_doubles" +COUNT=0 + +if [ $# -eq 0 ]; then + LOOP=false +else + LOOP=true +fi + +echo "" + +while true; do + + if [ $LOOP = true ]; then + if [ ! -d "$1" ]; then + echo "Can't chdir to $1." + exit 1 + else + echo "Changing directory to '$1'." + cd "$1" + shift + fi + else + echo "Working in directory '$(pwd)'." + fi + + sqlite3 $DATABASE "CREATE TABLE files (hash TEXT UNIQUE)" + mkdir -p $DIR + TMP=0 + for i in *; do + if [ -f "$i" ]; then + HASH=$(md5sum "$i" | awk '{ print $1 }') + sqlite3 $DATABASE "INSERT INTO files VALUES ('$HASH')" 2>/dev/null + if [ ! $? -eq 0 ]; then + mv -v "$i" "$DIR" + ((COUNT ++)) + ((TMP ++)) + fi + fi + done + + if [ $TMP -eq 0 ]; then + rmdir $DIR + fi + + if [ $LOOP = true ]; then + sqlite3 $DATABASE "DROP TABLE files" + echo "" + else + break + fi + + if [ $# -eq 0 ]; then + break; + fi +done + +echo "Found and moved $COUNT files to $DIR." +rm -f $DATABASE diff --git a/bin/duplicate_size.sh b/bin/duplicate_size.sh new file mode 100755 index 0000000..7ca2bf1 --- /dev/null +++ b/bin/duplicate_size.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +function usage() { + echo "Used to find the filesize of all duplicates found with duplicate.sh." + echo "Usage: eval \$(duplicate_size.sh)" + exit 1 +} + +if [ $# -gt 0 ]; then + usage +fi + +echo "FILE=\$(for i in **/found_doubles/*; do du -sb \"\$i\"; done); echo \$FILE | awk '{ sum+=\$1} END { print sum }'" |
