1

I'm running this code on shell

mv -f ~/sites/text1.txt  ~/sites/text2.txt;find ~/sites/ -type f -exec sha1sum {} >> ~/sites/text.txt \;diff ~/sites/text1.txt ~/sites/text2.txt;

However every time I'm having this error:

find: missing argument to `-exec'

Please anyone figure out how to get this code work?

2
  • 2
    find is expecting a terminator \;. You misplaced it after the redirect >>. You should have something like -exec sha1sum {} \; >> ~/sites/text.txt
    – alvits
    Dec 27, 2013 at 6:43
  • Thanks for figuring out it. Yes this is the problem.
    – inckka
    Dec 27, 2013 at 7:13

1 Answer 1

1
mv -f ~/sites.data/text1.txt  ~/sites.data/text2.txt &&\
find ~/sites/ -type f -print0|xarg0 -0r sha1sum |sort> ~/sites.data/text1.txt &&\
diff ~/sites.data/text1.txt ~/sites.data/text2.txt

changes I made: each command is now conditionally executed based on the success of the previous command, don't try to do io redirection from find-exec, terminate find-exec with semicolon (which must be escaped), included sequence number in io redirection, added sort to ensure repeatable order, moved data files out of search target to prevent them from listing themselves.

3
  • Thanks this is great. However I'm trying to compare two text file which contains over thousands of lines with some big web site's file list, so using the 'sort>' command would reduce the integrity of the task?
    – inckka
    Dec 27, 2013 at 7:11
  • depending on your system find may or may not be repeatable, If it is repeatable you don't need sort. I think you will need it or something similar.
    – hildred
    Dec 27, 2013 at 7:16
  • I found the sort command s required hear. Addition to this I'm having another problem, find ~/sites/ -type f -exec sha1sum {} \; |sort> ~/sites.data/text1.txt command takes more than 20 mnts to get completed. I need to diff to be run after that, however currently diff runs instantly without listning to && Is there any solution for this?
    – inckka
    Dec 28, 2013 at 2:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .