I have a .tgz file and want to make sure that it downloaded completely without any issues. Running `tar -tzf foo.tgz > /dev/null` takes about 30 seconds, which is a bit too long for my needs. I've heard that gzipped files have specific bytes at the end that indicate their validity. Is there a faster method, perhaps by checking the final bytes or using another command?
4 Answers
If you have a checksum for the file, that's the best way to ensure that your download matches what's expected. It guarantees the integrity of the file.
You can use `gzip -t foo.tgz` to quickly check if the gzip part of the file is valid. This should be much quicker than running a full `tar` test.
I tried a method where I truncated a file using: `cat a_random_tgz_in_my_home.tgz | head -c -1000 > defect.tgz` then ran `tar tf defect.tgz`. It resulted in 'Unexpected EOF in archive,' indicating not all the data is there.
Using checksums is really the best practice here. They help confirm that the file you downloaded is exactly what the original creator intended, avoiding issues with corrupted downloads.
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String