LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Copy and verify a directory in Linux (https://www.linuxquestions.org/questions/linux-newbie-8/copy-and-verify-a-directory-in-linux-4175459778/)

jismagic 04-27-2013 07:44 AM

Copy and verify a directory in Linux
 
Hello

I m transferring a folder from usb to local drive. I am using cp -r command to do it,
which works for me. But I want to verify if the file is transferred good.

I thought of 2 things - file size verification and CRC verification.

1, File size is different in usb drive and local drive - a few bytes different,
2. CRC verification is good.. but not sure how to do it..
I tried using cksum. is it OK to CRC a directory with cksum? If not, how i can
CRC all files in the directory?

3. Any other ideas?

thanks,
jis

Sigg3.net 04-27-2013 07:54 AM

Use 'sync' command to flush "temporary" data to disk. I always use this when transferring to USB devs.

Then, if you are paranoid, run md5sum on fileonpc vs fileonusb and see if the checksums are identical:
Code:

$ md5sum /home/file
123456767888999
$ md5sum /media/usb/file
123456767888999

This is just a mockup, but if the two numbers are identical the files are identical.

But if I understand you correctly, it's just about knowing that the data has actually been written. In that case, the sync command is your friend.

TobiSGD 04-27-2013 07:55 AM

Try to copy the files again, this time with rsync and the -c option. rsync will compare source and destination files based on a checksum before it copies and skip files that are the same in source and destination. So if rsync does not copy a file you can be sure that the copy is not corrupted.
Example:
Code:

cp -r /source /destination
rsync -avc /source /destination


eSelix 04-27-2013 07:57 AM

You can use md5sum for generating and checking:
Code:

md5sum /some_directory/* > checksum.md5
md5sum -c checksum.md5


hans66 07-29-2014 10:24 AM

https://sourceforge.net/projects/crcsum/ has cp & mv with crc checksum


All times are GMT -5. The time now is 07:53 AM.