Returning the MD5-hash of all files in a directory to a .txt file with file name

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I have a directory of pictures.



I need the MD5-hash of each file in that directory and the name of the file placed into a .txt document. This file is to be read at a later time to reference the MD5 and file name together.



Note:

I would like this to just pull all directory files with me specifying them.

I have tried playing with tar and find and I just cannot seem to find a good solution...



This is a directory example:



/Desktop/testing
RandomFilename1.png
RandomFilename2.png
RandomFilename3.png


The .txt output is:



RandomFilename1,da39a3ee5e6b4b0d3255bfef95601890afd80709
RandomFilename2,da39a3ee5e6b4b0d3255bfef95601890afd80709
RandomFilename3,da39a3ee5e6b4b0d3255bfef95601890afd80709


I've looked everywhere online with no luck.

This will be on a Linux terminal.










share|improve this question









New contributor




Grayson Moseley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • Do you really want the file names without the extension in the output? If so, what if two file names only differ in their extension?
    – dessert
    29 mins ago















up vote
2
down vote

favorite












I have a directory of pictures.



I need the MD5-hash of each file in that directory and the name of the file placed into a .txt document. This file is to be read at a later time to reference the MD5 and file name together.



Note:

I would like this to just pull all directory files with me specifying them.

I have tried playing with tar and find and I just cannot seem to find a good solution...



This is a directory example:



/Desktop/testing
RandomFilename1.png
RandomFilename2.png
RandomFilename3.png


The .txt output is:



RandomFilename1,da39a3ee5e6b4b0d3255bfef95601890afd80709
RandomFilename2,da39a3ee5e6b4b0d3255bfef95601890afd80709
RandomFilename3,da39a3ee5e6b4b0d3255bfef95601890afd80709


I've looked everywhere online with no luck.

This will be on a Linux terminal.










share|improve this question









New contributor




Grayson Moseley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • Do you really want the file names without the extension in the output? If so, what if two file names only differ in their extension?
    – dessert
    29 mins ago













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I have a directory of pictures.



I need the MD5-hash of each file in that directory and the name of the file placed into a .txt document. This file is to be read at a later time to reference the MD5 and file name together.



Note:

I would like this to just pull all directory files with me specifying them.

I have tried playing with tar and find and I just cannot seem to find a good solution...



This is a directory example:



/Desktop/testing
RandomFilename1.png
RandomFilename2.png
RandomFilename3.png


The .txt output is:



RandomFilename1,da39a3ee5e6b4b0d3255bfef95601890afd80709
RandomFilename2,da39a3ee5e6b4b0d3255bfef95601890afd80709
RandomFilename3,da39a3ee5e6b4b0d3255bfef95601890afd80709


I've looked everywhere online with no luck.

This will be on a Linux terminal.










share|improve this question









New contributor




Grayson Moseley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have a directory of pictures.



I need the MD5-hash of each file in that directory and the name of the file placed into a .txt document. This file is to be read at a later time to reference the MD5 and file name together.



Note:

I would like this to just pull all directory files with me specifying them.

I have tried playing with tar and find and I just cannot seem to find a good solution...



This is a directory example:



/Desktop/testing
RandomFilename1.png
RandomFilename2.png
RandomFilename3.png


The .txt output is:



RandomFilename1,da39a3ee5e6b4b0d3255bfef95601890afd80709
RandomFilename2,da39a3ee5e6b4b0d3255bfef95601890afd80709
RandomFilename3,da39a3ee5e6b4b0d3255bfef95601890afd80709


I've looked everywhere online with no luck.

This will be on a Linux terminal.







command-line find md5sum






share|improve this question









New contributor




Grayson Moseley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Grayson Moseley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 59 mins ago









muru

133k19280478




133k19280478






New contributor




Grayson Moseley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 3 hours ago









Grayson Moseley

111




111




New contributor




Grayson Moseley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Grayson Moseley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Grayson Moseley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • Do you really want the file names without the extension in the output? If so, what if two file names only differ in their extension?
    – dessert
    29 mins ago

















  • Do you really want the file names without the extension in the output? If so, what if two file names only differ in their extension?
    – dessert
    29 mins ago
















Do you really want the file names without the extension in the output? If so, what if two file names only differ in their extension?
– dessert
29 mins ago





Do you really want the file names without the extension in the output? If so, what if two file names only differ in their extension?
– dessert
29 mins ago











3 Answers
3






active

oldest

votes

















up vote
2
down vote













You can use the following bash command:



for file in testing/*; do md5sum $file; done > res.txt


Of course you have to adjust the destination directory of res.txt.

The result could look similar to this:



8b1500ea6fe42927891fd1831bb955ba testing/Pic1.gif
73f3222889a14411a3b78675ed0bc269 testing/Pic2.gif
c5b18ef1ea1346f13f668a7ead4e4c92 testing/Pic3.gif


So the MD5 hash is followed by the filename and path.






share|improve this answer


















  • 4




    The benefit of this solution is that you can later check the md5's with md5sum -c res.txt. I'd also suggest a simple md5sum *.gif > res.txt instead of a loop.
    – PerlDuck
    2 hours ago











  • Also, you should move the redirect outside the loop: for file ... done > res.txt, instead of opening and closing that file for each run of the loop.
    – muru
    57 mins ago










  • @muru: Thanks for your suggestion.
    – zx485
    53 mins ago

















up vote
1
down vote













For what you want to do, execute md5sum and use sed or awk to transform the output



md5sum *.png | sed 's/^([0-9a-f]+) +(.+)/2,1/' >images.md5sums
md5sum *.png | awk 'print $2","$1' >image.md5sums


However, the plain output of md5sum is hash filename and is equivalent to your format. Using that standard md5sum output format is often more convenient, since you can use it directly with md5sum -c to check the hash of the files (after a copy or network transfer). Some other utilities may also expect this particular format.






share|improve this answer





























    up vote
    -1
    down vote













    I have written a small script as per the parameters defined:



    cd /home/username/Desktop/testing
    for F in *
    do
    echo $F, $(md5sum $F | tr --delete $F)
    done


    Example output:



    1.txt, c8ef7cca2ceb3f87892bff63dbf9
    demo, 9470a3c74b32036fa148fabc70929
    line.cpp, 0732d27816b2b57d413f79f91fd28
    test, 37346996108d322767cf65f90d43c
    test.cpp, afb5b90f0021b6df4f98df40


    Note: This script would show the output in terminal. To save it in file you can use > 1.txt while executing the file, for e.g.:



    ./test.sh > 1.txt





    share|improve this answer






















    • You want to quote more, e.g. md5sum $F will throw errors in case of file names with spaces in it.
      – dessert
      32 mins ago










    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    Grayson Moseley is a new contributor. Be nice, and check out our Code of Conduct.









     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1090582%2freturning-the-md5-hash-of-all-files-in-a-directory-to-a-txt-file-with-file-name%23new-answer', 'question_page');

    );

    Post as a guest






























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote













    You can use the following bash command:



    for file in testing/*; do md5sum $file; done > res.txt


    Of course you have to adjust the destination directory of res.txt.

    The result could look similar to this:



    8b1500ea6fe42927891fd1831bb955ba testing/Pic1.gif
    73f3222889a14411a3b78675ed0bc269 testing/Pic2.gif
    c5b18ef1ea1346f13f668a7ead4e4c92 testing/Pic3.gif


    So the MD5 hash is followed by the filename and path.






    share|improve this answer


















    • 4




      The benefit of this solution is that you can later check the md5's with md5sum -c res.txt. I'd also suggest a simple md5sum *.gif > res.txt instead of a loop.
      – PerlDuck
      2 hours ago











    • Also, you should move the redirect outside the loop: for file ... done > res.txt, instead of opening and closing that file for each run of the loop.
      – muru
      57 mins ago










    • @muru: Thanks for your suggestion.
      – zx485
      53 mins ago














    up vote
    2
    down vote













    You can use the following bash command:



    for file in testing/*; do md5sum $file; done > res.txt


    Of course you have to adjust the destination directory of res.txt.

    The result could look similar to this:



    8b1500ea6fe42927891fd1831bb955ba testing/Pic1.gif
    73f3222889a14411a3b78675ed0bc269 testing/Pic2.gif
    c5b18ef1ea1346f13f668a7ead4e4c92 testing/Pic3.gif


    So the MD5 hash is followed by the filename and path.






    share|improve this answer


















    • 4




      The benefit of this solution is that you can later check the md5's with md5sum -c res.txt. I'd also suggest a simple md5sum *.gif > res.txt instead of a loop.
      – PerlDuck
      2 hours ago











    • Also, you should move the redirect outside the loop: for file ... done > res.txt, instead of opening and closing that file for each run of the loop.
      – muru
      57 mins ago










    • @muru: Thanks for your suggestion.
      – zx485
      53 mins ago












    up vote
    2
    down vote










    up vote
    2
    down vote









    You can use the following bash command:



    for file in testing/*; do md5sum $file; done > res.txt


    Of course you have to adjust the destination directory of res.txt.

    The result could look similar to this:



    8b1500ea6fe42927891fd1831bb955ba testing/Pic1.gif
    73f3222889a14411a3b78675ed0bc269 testing/Pic2.gif
    c5b18ef1ea1346f13f668a7ead4e4c92 testing/Pic3.gif


    So the MD5 hash is followed by the filename and path.






    share|improve this answer














    You can use the following bash command:



    for file in testing/*; do md5sum $file; done > res.txt


    Of course you have to adjust the destination directory of res.txt.

    The result could look similar to this:



    8b1500ea6fe42927891fd1831bb955ba testing/Pic1.gif
    73f3222889a14411a3b78675ed0bc269 testing/Pic2.gif
    c5b18ef1ea1346f13f668a7ead4e4c92 testing/Pic3.gif


    So the MD5 hash is followed by the filename and path.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 34 mins ago









    dessert

    20.7k55896




    20.7k55896










    answered 3 hours ago









    zx485

    1,33521114




    1,33521114







    • 4




      The benefit of this solution is that you can later check the md5's with md5sum -c res.txt. I'd also suggest a simple md5sum *.gif > res.txt instead of a loop.
      – PerlDuck
      2 hours ago











    • Also, you should move the redirect outside the loop: for file ... done > res.txt, instead of opening and closing that file for each run of the loop.
      – muru
      57 mins ago










    • @muru: Thanks for your suggestion.
      – zx485
      53 mins ago












    • 4




      The benefit of this solution is that you can later check the md5's with md5sum -c res.txt. I'd also suggest a simple md5sum *.gif > res.txt instead of a loop.
      – PerlDuck
      2 hours ago











    • Also, you should move the redirect outside the loop: for file ... done > res.txt, instead of opening and closing that file for each run of the loop.
      – muru
      57 mins ago










    • @muru: Thanks for your suggestion.
      – zx485
      53 mins ago







    4




    4




    The benefit of this solution is that you can later check the md5's with md5sum -c res.txt. I'd also suggest a simple md5sum *.gif > res.txt instead of a loop.
    – PerlDuck
    2 hours ago





    The benefit of this solution is that you can later check the md5's with md5sum -c res.txt. I'd also suggest a simple md5sum *.gif > res.txt instead of a loop.
    – PerlDuck
    2 hours ago













    Also, you should move the redirect outside the loop: for file ... done > res.txt, instead of opening and closing that file for each run of the loop.
    – muru
    57 mins ago




    Also, you should move the redirect outside the loop: for file ... done > res.txt, instead of opening and closing that file for each run of the loop.
    – muru
    57 mins ago












    @muru: Thanks for your suggestion.
    – zx485
    53 mins ago




    @muru: Thanks for your suggestion.
    – zx485
    53 mins ago












    up vote
    1
    down vote













    For what you want to do, execute md5sum and use sed or awk to transform the output



    md5sum *.png | sed 's/^([0-9a-f]+) +(.+)/2,1/' >images.md5sums
    md5sum *.png | awk 'print $2","$1' >image.md5sums


    However, the plain output of md5sum is hash filename and is equivalent to your format. Using that standard md5sum output format is often more convenient, since you can use it directly with md5sum -c to check the hash of the files (after a copy or network transfer). Some other utilities may also expect this particular format.






    share|improve this answer


























      up vote
      1
      down vote













      For what you want to do, execute md5sum and use sed or awk to transform the output



      md5sum *.png | sed 's/^([0-9a-f]+) +(.+)/2,1/' >images.md5sums
      md5sum *.png | awk 'print $2","$1' >image.md5sums


      However, the plain output of md5sum is hash filename and is equivalent to your format. Using that standard md5sum output format is often more convenient, since you can use it directly with md5sum -c to check the hash of the files (after a copy or network transfer). Some other utilities may also expect this particular format.






      share|improve this answer
























        up vote
        1
        down vote










        up vote
        1
        down vote









        For what you want to do, execute md5sum and use sed or awk to transform the output



        md5sum *.png | sed 's/^([0-9a-f]+) +(.+)/2,1/' >images.md5sums
        md5sum *.png | awk 'print $2","$1' >image.md5sums


        However, the plain output of md5sum is hash filename and is equivalent to your format. Using that standard md5sum output format is often more convenient, since you can use it directly with md5sum -c to check the hash of the files (after a copy or network transfer). Some other utilities may also expect this particular format.






        share|improve this answer














        For what you want to do, execute md5sum and use sed or awk to transform the output



        md5sum *.png | sed 's/^([0-9a-f]+) +(.+)/2,1/' >images.md5sums
        md5sum *.png | awk 'print $2","$1' >image.md5sums


        However, the plain output of md5sum is hash filename and is equivalent to your format. Using that standard md5sum output format is often more convenient, since you can use it directly with md5sum -c to check the hash of the files (after a copy or network transfer). Some other utilities may also expect this particular format.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 34 mins ago









        dessert

        20.7k55896




        20.7k55896










        answered 1 hour ago









        xenoid

        1,2861314




        1,2861314




















            up vote
            -1
            down vote













            I have written a small script as per the parameters defined:



            cd /home/username/Desktop/testing
            for F in *
            do
            echo $F, $(md5sum $F | tr --delete $F)
            done


            Example output:



            1.txt, c8ef7cca2ceb3f87892bff63dbf9
            demo, 9470a3c74b32036fa148fabc70929
            line.cpp, 0732d27816b2b57d413f79f91fd28
            test, 37346996108d322767cf65f90d43c
            test.cpp, afb5b90f0021b6df4f98df40


            Note: This script would show the output in terminal. To save it in file you can use > 1.txt while executing the file, for e.g.:



            ./test.sh > 1.txt





            share|improve this answer






















            • You want to quote more, e.g. md5sum $F will throw errors in case of file names with spaces in it.
              – dessert
              32 mins ago














            up vote
            -1
            down vote













            I have written a small script as per the parameters defined:



            cd /home/username/Desktop/testing
            for F in *
            do
            echo $F, $(md5sum $F | tr --delete $F)
            done


            Example output:



            1.txt, c8ef7cca2ceb3f87892bff63dbf9
            demo, 9470a3c74b32036fa148fabc70929
            line.cpp, 0732d27816b2b57d413f79f91fd28
            test, 37346996108d322767cf65f90d43c
            test.cpp, afb5b90f0021b6df4f98df40


            Note: This script would show the output in terminal. To save it in file you can use > 1.txt while executing the file, for e.g.:



            ./test.sh > 1.txt





            share|improve this answer






















            • You want to quote more, e.g. md5sum $F will throw errors in case of file names with spaces in it.
              – dessert
              32 mins ago












            up vote
            -1
            down vote










            up vote
            -1
            down vote









            I have written a small script as per the parameters defined:



            cd /home/username/Desktop/testing
            for F in *
            do
            echo $F, $(md5sum $F | tr --delete $F)
            done


            Example output:



            1.txt, c8ef7cca2ceb3f87892bff63dbf9
            demo, 9470a3c74b32036fa148fabc70929
            line.cpp, 0732d27816b2b57d413f79f91fd28
            test, 37346996108d322767cf65f90d43c
            test.cpp, afb5b90f0021b6df4f98df40


            Note: This script would show the output in terminal. To save it in file you can use > 1.txt while executing the file, for e.g.:



            ./test.sh > 1.txt





            share|improve this answer














            I have written a small script as per the parameters defined:



            cd /home/username/Desktop/testing
            for F in *
            do
            echo $F, $(md5sum $F | tr --delete $F)
            done


            Example output:



            1.txt, c8ef7cca2ceb3f87892bff63dbf9
            demo, 9470a3c74b32036fa148fabc70929
            line.cpp, 0732d27816b2b57d413f79f91fd28
            test, 37346996108d322767cf65f90d43c
            test.cpp, afb5b90f0021b6df4f98df40


            Note: This script would show the output in terminal. To save it in file you can use > 1.txt while executing the file, for e.g.:



            ./test.sh > 1.txt






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 33 mins ago









            dessert

            20.7k55896




            20.7k55896










            answered 3 hours ago









            Kulfy

            2,0592831




            2,0592831











            • You want to quote more, e.g. md5sum $F will throw errors in case of file names with spaces in it.
              – dessert
              32 mins ago
















            • You want to quote more, e.g. md5sum $F will throw errors in case of file names with spaces in it.
              – dessert
              32 mins ago















            You want to quote more, e.g. md5sum $F will throw errors in case of file names with spaces in it.
            – dessert
            32 mins ago




            You want to quote more, e.g. md5sum $F will throw errors in case of file names with spaces in it.
            – dessert
            32 mins ago










            Grayson Moseley is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            Grayson Moseley is a new contributor. Be nice, and check out our Code of Conduct.












            Grayson Moseley is a new contributor. Be nice, and check out our Code of Conduct.











            Grayson Moseley is a new contributor. Be nice, and check out our Code of Conduct.













             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1090582%2freturning-the-md5-hash-of-all-files-in-a-directory-to-a-txt-file-with-file-name%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            Installing NextGIS Connect into QGIS 3?

            One-line joke