~ubuntu-branches/ubuntu/wily/duff/wily

« back to all changes in this revision

Viewing changes to join-duplicates.sh

  • Committer: Package Import Robot
  • Author(s): Kamal Mostafa
  • Date: 2012-01-29 08:02:46 UTC
  • Revision ID: package-import@ubuntu.com-20120129080246-jd9w62dkx0v5q7r1
Tags: upstream-0.5.2
ImportĀ upstreamĀ versionĀ 0.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
# Example script for duff(1).
 
4
#
 
5
# Copyright (c) 2005 Ross Newell
 
6
#
 
7
# Modified Jan 7, 2006 by Camilla Berglund <elmindreda@elmindreda.org>
 
8
#
 
9
# Uses duff to find duplicate physical files and changes them into hard links
 
10
# to a single physical file, thus saving disk space.  Use with care.
 
11
#
 
12
 
 
13
if [ "$1" == '' ]; then
 
14
  echo "usage: `basename $0` directory"
 
15
  exit 1
 
16
fi
 
17
 
 
18
duff -r '-f#' -z -p -P "$1" |
 
19
(
 
20
  while read file 
 
21
  do
 
22
    if [ "$file" == '#' ]; then
 
23
      first=''
 
24
    else
 
25
      if [ "$first" == '' ]; then
 
26
        first="$file"
 
27
      else
 
28
        temp=`mktemp -p \`dirname $file\``
 
29
 
 
30
        mv "$file" "$temp" && \
 
31
        ln "$first" "$file" && \
 
32
        touch --reference="$temp" "$file" && \
 
33
        rm "$temp"
 
34
 
 
35
        if [ $? != 0 ]; then
 
36
          echo "`basename $0`: $file: failed to join with $first"
 
37
          echo "`basename $0`: $file: may exist as $temp"
 
38
          exit 1
 
39
        fi
 
40
      fi
 
41
    fi
 
42
  done
 
43
)
 
44