Search code examples
bashmd5sumfilelist

md5sum of certain files in two different folders in bash


I want to copy files from folderA to folderB, where some of the copied files are written over existing files in folderB. folderB also contains files, which are not in folderA. After the operation I want to compare the md5sum of all the copied files in folders A and B.

How can I produce a list of files in folderA and pipe it to md5sum in folderB? I tried:

 ls -1 | md5sum

but 'ls -1' is not a list of different files for md5sum...

Many thanks


Solution

  • I guess you want to generate the md5sum of the files in folderA and the equivalent files in folderB:

    cd folderA
    md5sum *
    cd folderB
    ( cd folderA && ls ) | xargs md5sum
    

    However you might want to look at diff instead to check. And maybe rsync for doing the copying.