Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-27-2013, 08:44 AM   #1
LQ Newbie
Registered: Apr 2013
Posts: 1

Rep: Reputation: Disabled
Copy and verify a directory in Linux


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?

Old 04-27-2013, 08:54 AM   #2
Registered: Mar 2008
Location: Oslo, Norway
Distribution: Slackware 14.1 64-bit, Ubuntu 15.10, Fedora 17, Ubuntu 12 LTS and Ubuntu server 10.04
Posts: 168

Rep: Reputation: 23
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:
$ md5sum /home/file
$ md5sum /media/usb/file
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.

Last edited by; 04-27-2013 at 08:56 AM.
Old 04-27-2013, 08:55 AM   #3
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4852Reputation: 4852Reputation: 4852Reputation: 4852Reputation: 4852Reputation: 4852Reputation: 4852Reputation: 4852Reputation: 4852Reputation: 4852Reputation: 4852
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.
cp -r /source /destination
rsync -avc /source /destination
Old 04-27-2013, 08:57 AM   #4
Senior Member
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,254

Rep: Reputation: 314Reputation: 314Reputation: 314Reputation: 314
You can use md5sum for generating and checking:
md5sum /some_directory/* > checksum.md5
md5sum -c checksum.md5
Old 07-29-2014, 11:24 AM   #5
LQ Newbie
Registered: Jul 2014
Posts: 2

Rep: Reputation: Disabled has cp & mv with crc checksum


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Does Linux verify copy and save ? mistofeles Linux - Newbie 4 01-31-2012 07:33 AM
How can I use Linux to copy binary files to a new directory lnx_learner Linux - Newbie 1 01-07-2008 12:37 PM
verify directory creation shifter Programming 5 06-28-2007 03:28 AM
How do you GPG verify all of your rsync slackware directory Old_Fogie Slackware 31 10-24-2006 07:27 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:48 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration