Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've been using the following command line to do recursive checksumming of directories. It seems to get the job done, but still being a newbie I've been wondering, are there any potential problems with doing it this way? Is it possible for this command to miss files or otherwise mess up?

find ./dir/ -type f -exec sha1sum {} \; > files.sha1
share|improve this question
    
You could use + instead of \;. That way multiple files are passed to sha1sum instead of starting a new sha1sum for each file. Otherwise it looks good. –  Adaephon Mar 26 at 14:19

1 Answer 1

up vote 2 down vote accepted

There's nothing wrong I can see with your approach. You're excluding directories and find will include hidden files by default. Yeah, it's fine.

But I'll offer you an alternative because that's what I do:

shopt -s globstar dotglob
sha1sum **

globstar enables a recursive match for ** and dotglob enables matching hidden files. Between them they expand to all the filenames and sha1sum can parse them all.

The main problem with this approach is it will pass all the filenames off to sha1sum in one fat pile. While this can be somewhat faster at small loads, it will explode if you have too many filenames. I don't know what the cut-off is.

share|improve this answer
    
The cutoff is ARG_MAX, the size of a command's arguments,, you can get the value for your system with getconf ARG_MAX. –  terdon Mar 26 at 15:42

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.