There are two directories with many files. Those files are always matching in names and not always matching in size. For example:
/dir1
|-file1 (1 MB)
|-file2 (2 MB)
|-file3 (3 MB)
/dir2
|-file1 (1 KB)
|-file2 (2 MB)
|-file3 (10 MB)
As you see, filenames are match but filesize matches only in file2. How can I compare files in those 2 directories and select files only which are bigger? Output in example case must be "/dir2/file3".
If there is a file in dir1 that is bigger than the file with the same name in dir2 = then do nothing. I am interested only about files in dir2 that are bigger than ones in dir1
I've wrote a script, but it works only if one bigger file in dir2 was found.
#!/bin/bash
diff -q $1 $2 | awk '{ print $2,$4 }' > tempfile.txt
A=`cat tempfile.txt | cut -d ' ' -f 1`
B=`ls -s $A | cut -d ' ' -f 1`
C=`cat tempfile.txt | cut -d ' ' -f 2`
D=`ls -s $C | cut -d ' ' -f 1`
if [ "$D" -gt "$B" ]; then
echo $C
fi
dir1
that is bigger than the file with the same name indir2
? – Niko Gambt Jan 23 '19 at 03:46diff -q dir1/ dir2/
– Panki Jan 23 '19 at 07:41