Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a directory that have zillions of files. As soon as I try to copy this directory, I receive a message that a file could not be copied (corrupt ?) and the copy stops.

Is there any command I can type on terminal that can check all files on that directory tree and list all files that could not be copied or that are corrupt? I would not like to copy the files at this time, just to check if files would not be possible to copy/read if I try.

I am on OS X Mountain Lion but any unix command should work fine, I hope.

thanks.

NOTE: by corrupt I mean a file that cannot be read or copied.

share|improve this question
    
Note that the best solution of course is to use a competent filesystem that's able to detect and fix corruption. A monthly run of zpool scrub zroot is a good way to ensure you never lose data. –  Nicholas Wilson Sep 29 '12 at 21:39

1 Answer 1

up vote 5 down vote accepted
  1. rsync can be used to copy directories, and is capable of restarting the copy from the point at which it terminated if any error causes the rsync to die.

    Using rsync's --dry-run option you can see what would be copied without actually copying anything. The --stats and --progress options would also be useful. and --human-readable or -h is easier to read.

    e.g.

    rsync --dry-run -avh --stats --progress /path/to/src/ /path/to/destination/

    I'm not sure if rsync is installed by default on Mac OS X, but I have used it on Macs so I know it's definitely available.

  2. For a quick-and-dirty check on whether files in a subdirectory can be read or not, you could use grep -r XXX /path/to/directory/ > /dev/null. The search regexp doesn't matter, because output is being discarded anyway.

    STDOUT is being redirected to /dev/null, so you'll only see errors.

    The only reason I chose grep here was because of its -r recursion option. There are many other commands that could be used instead of grep here, and even more if used with find.

share|improve this answer
    
Thanks! I will try that!!!!! –  Digital Robot Sep 29 '12 at 18:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.