So I want to sum and display the sum of the size of the files that are solely included in directory1
but not in directory2
. However, according to my code, this is done for only one file of the directory, how can I make it work for multiple files? The code below is where the problem is found:
#!/bin/bash
dir1=$1
dir2=$2
echo Files that are included only in directory1 and not in directory2
diff $dir1 $dir2 | egrep $dir1 | wc -l
diff $dir1 $dir2 | egrep $dir1
files=$(diff $dir1 $dir2 |egrep $dir1 |awk '{print $4}')
ls -l ./$dir1/$files | awk '{t+=$5}END{print t}'
du -c file [file..]
will give you the sum of the disk space used by the arguments (or the sum of their file size if you use--apparent-size
). It can also use an exclusion list (-exclude-from=FILE
), so you could call it on dir1 using the dir2 contents as the exclusion list...