mktar: Use `wc` instead of `du` in summary message
[sunny256-utils.git] / rmdup
blobd41a9ab06ed8dbfe41591fe8f56c3d5a5abd51cf
1 #!/usr/bin/env bash
3 #==============================================================================
4 # rmdup
5 # File ID: 6fc9b9b8-5d43-11df-ab40-90e6ba3022ac
6 # Compares the files in directory $1 with existing files in directory $2
7 # and removes the duplicates in directory $2.
8 #==============================================================================
10 if [ $# -ne 2 ]; then
11 echo $0: Invalid number of operands \($#\), shall be two. >&2
12 exit 1
15 if [ ! -d "$1" ]; then
16 echo $0: Operand 1 \($1\) is not a directory >$2
17 exit 1
20 if [ ! -d "$2" ]; then
21 echo $0: Operand 2 \($2\) is not a directory >&2
22 exit 1
25 # BUG: Has to check that $1 and $2 are different dirs. Now it checks inode
26 # on every file, it might skip files if they has the same link, but better
27 # safe than sorry.
29 # Also... Files with weird names (spaces etc) could have unwanted results.
30 # A check should be done for things like that. Later.
32 # Future check for weird names
33 # find $1 $2 | grep -e ' ' -e '\t' -e ';' -e '&' -e '|' || { echo farsken; exit 1; }
34 # echo hurra
35 # exit
37 for _qqrc in $1/*; do
38 _qqr2="$2/`basename $_qqrc`"
39 if [ -f "$_qqrc" -a -f "$_qqr2" ]; then
40 if [ "$_qqrc" -ef "$_qqr2" ]; then
41 echo $0: File $_qqrc and $_qqr2 are the same >&2
42 else
43 diff -q "$_qqrc" "$_qqr2" >/dev/null
44 if [ $? -eq 0 ]; then
45 rm -v "$_qqr2"
46 else
47 echo $_qqrc og $_qqr2 are not equal
51 done