Melakukan beberapa pengujian dengan Raspberry Pi 3B + (Saya menggunakan sistem file overlay, dan perlu disinkronkan secara berkala), saya menjalankan perbandingan sendiri untuk diff -q dan cmp -s; perhatikan bahwa ini adalah log dari dalam / dev / shm, jadi kecepatan akses disk adalah bukan masalah:
[root@mypi shm]# dd if=/dev/urandom of=test.file bs=1M count=100 ; time diff -q test.file test.copy && echo diff true || echo diff false ; time cmp -s test.file test.copy && echo cmp true || echo cmp false ; cp -a test.file test.copy ; time diff -q test.file test.copy && echo diff true || echo diff false; time cmp -s test.file test.copy && echo cmp true || echo cmp false
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 6.2564 s, 16.8 MB/s
Files test.file and test.copy differ
real 0m0.008s
user 0m0.008s
sys 0m0.000s
diff false
real 0m0.009s
user 0m0.007s
sys 0m0.001s
cmp false
cp: overwrite âtest.copyâ? y
real 0m0.966s
user 0m0.447s
sys 0m0.518s
diff true
real 0m0.785s
user 0m0.211s
sys 0m0.573s
cmp true
[root@mypi shm]# pico /root/rwbscripts/utils/squish.sh
Saya menjalankannya beberapa kali. cmp -s secara konsisten memiliki waktu yang sedikit lebih pendek pada kotak tes yang saya gunakan. Jadi jika Anda ingin menggunakan cmp -s untuk melakukan hal-hal antara dua file ....
identical (){
echo "$1" and "$2" are the same.
echo This is a function, you can put whatever you want in here.
}
different () {
echo "$1" and "$2" are different.
echo This is a function, you can put whatever you want in here, too.
}
cmp -s "$FILEA" "$FILEB" && identical "$FILEA" "$FILEB" || different "$FILEA" "$FILEB"