How to compare the ls output of two folders to find a missing directory?Compare two folders for missing filesHow do you compare two folders and copy the difference to a third folder?given a file, find where within a subdirectory it was copied tomerge two image foldersFind differences of ownerships between two home folders?Streaming compare the contents in two directoryMove files that have the same case-insensitive filenameHow should I merge two folders on the same filesystem?Print Folders Missing .txt FiletypeCompare two directories for a certain extension and then move the missing ones to a new directoryCompare two folders for missing files

How can a dictatorship government be beneficial to a dictator in a post-scarcity society?

What happens to unproductive professors?

Why did Old English lose both thorn and eth?

Is it possible to see individual photons impressioning film?

Given a 32 bit number, what is an efficient way to scale each byte by a certain factor?

Integer Lists of Noah

Could you brine steak?

Why is the ladder of the LM always in the dark side of the LM?

Reverse dots and boxes

How do you move up one folder in Finder?

What is the right approach to quit a job during probation period for a competing offer?

Is there a nice way to implement a conditional type with default fail case?

Do I have to worry about delays in international trains? (UK, Belgium, Germany)

What happens when adult Billy Batson says "Shazam"?

How to drill holes in 3/8" steel plates?

Is that a case of "DOUBLE-NEGATIVES" as claimed by Grammarly?

What are some further readings in Econometrics you recommend?

How effective would wooden scale armor be in a medieval setting?

Why did Harry Potter get a bedroom?

Did the Ottoman empire suppress the printing press?

Why is a mixture of two normally distributed variables only bimodal if their means differ by at least two times the common standard deviation?

When did "&" stop being taught alongside the alphabet?

Is there a method for differentiating informative comments from commented out code?

What are the original Russian words for a prostitute?



How to compare the ls output of two folders to find a missing directory?


Compare two folders for missing filesHow do you compare two folders and copy the difference to a third folder?given a file, find where within a subdirectory it was copied tomerge two image foldersFind differences of ownerships between two home folders?Streaming compare the contents in two directoryMove files that have the same case-insensitive filenameHow should I merge two folders on the same filesystem?Print Folders Missing .txt FiletypeCompare two directories for a certain extension and then move the missing ones to a new directoryCompare two folders for missing files






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















I'm trying to compare a folder with 1400 subfolders to one with a 1.399. I need to know which subfolder is missing.



I tried this:



diff -rq dir1/ dir2/ | grep dir1/ | awk 'print $4' > difference1.txt


But it's been like 6 hours yet and no output. ls in the folders is nearly instant so is there a faster approach than diff?










share|improve this question






















  • Answered in stackoverflow.com/questions/4997693/…

    – GMaster
    8 hours ago











  • @GMaster I'm asking for a faster approach

    – Freedo
    8 hours ago











  • Sounds similar to unix.stackexchange.com/q/524074/117549

    – Jeff Schaller
    7 hours ago

















3















I'm trying to compare a folder with 1400 subfolders to one with a 1.399. I need to know which subfolder is missing.



I tried this:



diff -rq dir1/ dir2/ | grep dir1/ | awk 'print $4' > difference1.txt


But it's been like 6 hours yet and no output. ls in the folders is nearly instant so is there a faster approach than diff?










share|improve this question






















  • Answered in stackoverflow.com/questions/4997693/…

    – GMaster
    8 hours ago











  • @GMaster I'm asking for a faster approach

    – Freedo
    8 hours ago











  • Sounds similar to unix.stackexchange.com/q/524074/117549

    – Jeff Schaller
    7 hours ago













3












3








3








I'm trying to compare a folder with 1400 subfolders to one with a 1.399. I need to know which subfolder is missing.



I tried this:



diff -rq dir1/ dir2/ | grep dir1/ | awk 'print $4' > difference1.txt


But it's been like 6 hours yet and no output. ls in the folders is nearly instant so is there a faster approach than diff?










share|improve this question














I'm trying to compare a folder with 1400 subfolders to one with a 1.399. I need to know which subfolder is missing.



I tried this:



diff -rq dir1/ dir2/ | grep dir1/ | awk 'print $4' > difference1.txt


But it's been like 6 hours yet and no output. ls in the folders is nearly instant so is there a faster approach than diff?







files






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 8 hours ago









FreedoFreedo

4826 silver badges24 bronze badges




4826 silver badges24 bronze badges












  • Answered in stackoverflow.com/questions/4997693/…

    – GMaster
    8 hours ago











  • @GMaster I'm asking for a faster approach

    – Freedo
    8 hours ago











  • Sounds similar to unix.stackexchange.com/q/524074/117549

    – Jeff Schaller
    7 hours ago

















  • Answered in stackoverflow.com/questions/4997693/…

    – GMaster
    8 hours ago











  • @GMaster I'm asking for a faster approach

    – Freedo
    8 hours ago











  • Sounds similar to unix.stackexchange.com/q/524074/117549

    – Jeff Schaller
    7 hours ago
















Answered in stackoverflow.com/questions/4997693/…

– GMaster
8 hours ago





Answered in stackoverflow.com/questions/4997693/…

– GMaster
8 hours ago













@GMaster I'm asking for a faster approach

– Freedo
8 hours ago





@GMaster I'm asking for a faster approach

– Freedo
8 hours ago













Sounds similar to unix.stackexchange.com/q/524074/117549

– Jeff Schaller
7 hours ago





Sounds similar to unix.stackexchange.com/q/524074/117549

– Jeff Schaller
7 hours ago










3 Answers
3






active

oldest

votes


















2














This is a fairly simple task for rsync.



rsync -n -av dir1/ dir2/ | grep '/$' | grep -Fvx './'



This does a dry run of rsyncing dir1's contents into dir2, and displays only the lines ending in a slash (the directories), except possibly for the top-level directory itself.



Here's a simple test/demo:



$ # create 1500 folders in dir1:
$ for i in $(jot -w %04d 1500); do mkdir -p dir1/dir-$i; done
$ # clone dir1 to dir2, then remove one directory:
$ rsync -a dir1/ dir2/
$ rmdir dir2/dir-0749/
$ # rsync -n will tell you which one is missing:
$ time rsync -n -av dir1/ dir2/ | grep '/$' | grep -Fvx './'
dir-0749/

real 0m0.038s
user 0m0.001s
sys 0m0.041s


If you would like to adapt this technique to also check for folders missing from dir1 but present in dir2, use rsync's --delete option:



$ rmdir dir1/dir-0479/
$ time rsync -nav --delete dir1/ dir2/ | grep '/$' | grep -Fvx './'
deleting dir-0479/
dir-0749/


The deleting ... line tells you that dir-0479 is absent from dir1 but present in dir2.






share|improve this answer






























    1














    Try either
    ls dir1 > file1; ls dir2 > file2; diff file1 file2



    or if you have vimdiff and tree which is the most useful way with sub directories, you could use



    tree dir1 > file1; tree dir2 > fiel2; vimdiff file1 file2



    Though, running ls is much faster than tree which is what you are after.



    If the difference is in a sub-directory in dir1
    eg.



    dir1
    - dir2
    - dir3
    - dir4
    vs

    dir2
    - dir2
    - dir3


    You would need to do



    ls -R dir1 > file1; ls -R dir2 > file2; vimdiff file1 file2






    share|improve this answer










    New contributor



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


























      1














      diff -u <(ls dir1) <(ls dir2)


      This will make sure diff does not look inside the subdirs.



      Or try this if you are brave ;)



      diff -u <(find dir1/ -maxdepth 1 -type d -exec basename ;) <(find dir2/ -maxdepth 1 -type d -exec basename ;)





      share|improve this answer

























      • diff -u <(cd dir1; find -type d | sort) <(cd dir2; find -type d | sort) ?

        – Hannu
        8 hours ago






      • 1





        =) ............

        – Hannu
        8 hours ago











      • comm -23 <(ls /dir1 |sort) <(ls /dir2 |sort) also worked for me and was very fast too

        – Freedo
        7 hours ago













      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "106"
      ;
      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',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      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
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f528988%2fhow-to-compare-the-ls-output-of-two-folders-to-find-a-missing-directory%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      This is a fairly simple task for rsync.



      rsync -n -av dir1/ dir2/ | grep '/$' | grep -Fvx './'



      This does a dry run of rsyncing dir1's contents into dir2, and displays only the lines ending in a slash (the directories), except possibly for the top-level directory itself.



      Here's a simple test/demo:



      $ # create 1500 folders in dir1:
      $ for i in $(jot -w %04d 1500); do mkdir -p dir1/dir-$i; done
      $ # clone dir1 to dir2, then remove one directory:
      $ rsync -a dir1/ dir2/
      $ rmdir dir2/dir-0749/
      $ # rsync -n will tell you which one is missing:
      $ time rsync -n -av dir1/ dir2/ | grep '/$' | grep -Fvx './'
      dir-0749/

      real 0m0.038s
      user 0m0.001s
      sys 0m0.041s


      If you would like to adapt this technique to also check for folders missing from dir1 but present in dir2, use rsync's --delete option:



      $ rmdir dir1/dir-0479/
      $ time rsync -nav --delete dir1/ dir2/ | grep '/$' | grep -Fvx './'
      deleting dir-0479/
      dir-0749/


      The deleting ... line tells you that dir-0479 is absent from dir1 but present in dir2.






      share|improve this answer



























        2














        This is a fairly simple task for rsync.



        rsync -n -av dir1/ dir2/ | grep '/$' | grep -Fvx './'



        This does a dry run of rsyncing dir1's contents into dir2, and displays only the lines ending in a slash (the directories), except possibly for the top-level directory itself.



        Here's a simple test/demo:



        $ # create 1500 folders in dir1:
        $ for i in $(jot -w %04d 1500); do mkdir -p dir1/dir-$i; done
        $ # clone dir1 to dir2, then remove one directory:
        $ rsync -a dir1/ dir2/
        $ rmdir dir2/dir-0749/
        $ # rsync -n will tell you which one is missing:
        $ time rsync -n -av dir1/ dir2/ | grep '/$' | grep -Fvx './'
        dir-0749/

        real 0m0.038s
        user 0m0.001s
        sys 0m0.041s


        If you would like to adapt this technique to also check for folders missing from dir1 but present in dir2, use rsync's --delete option:



        $ rmdir dir1/dir-0479/
        $ time rsync -nav --delete dir1/ dir2/ | grep '/$' | grep -Fvx './'
        deleting dir-0479/
        dir-0749/


        The deleting ... line tells you that dir-0479 is absent from dir1 but present in dir2.






        share|improve this answer

























          2












          2








          2







          This is a fairly simple task for rsync.



          rsync -n -av dir1/ dir2/ | grep '/$' | grep -Fvx './'



          This does a dry run of rsyncing dir1's contents into dir2, and displays only the lines ending in a slash (the directories), except possibly for the top-level directory itself.



          Here's a simple test/demo:



          $ # create 1500 folders in dir1:
          $ for i in $(jot -w %04d 1500); do mkdir -p dir1/dir-$i; done
          $ # clone dir1 to dir2, then remove one directory:
          $ rsync -a dir1/ dir2/
          $ rmdir dir2/dir-0749/
          $ # rsync -n will tell you which one is missing:
          $ time rsync -n -av dir1/ dir2/ | grep '/$' | grep -Fvx './'
          dir-0749/

          real 0m0.038s
          user 0m0.001s
          sys 0m0.041s


          If you would like to adapt this technique to also check for folders missing from dir1 but present in dir2, use rsync's --delete option:



          $ rmdir dir1/dir-0479/
          $ time rsync -nav --delete dir1/ dir2/ | grep '/$' | grep -Fvx './'
          deleting dir-0479/
          dir-0749/


          The deleting ... line tells you that dir-0479 is absent from dir1 but present in dir2.






          share|improve this answer













          This is a fairly simple task for rsync.



          rsync -n -av dir1/ dir2/ | grep '/$' | grep -Fvx './'



          This does a dry run of rsyncing dir1's contents into dir2, and displays only the lines ending in a slash (the directories), except possibly for the top-level directory itself.



          Here's a simple test/demo:



          $ # create 1500 folders in dir1:
          $ for i in $(jot -w %04d 1500); do mkdir -p dir1/dir-$i; done
          $ # clone dir1 to dir2, then remove one directory:
          $ rsync -a dir1/ dir2/
          $ rmdir dir2/dir-0749/
          $ # rsync -n will tell you which one is missing:
          $ time rsync -n -av dir1/ dir2/ | grep '/$' | grep -Fvx './'
          dir-0749/

          real 0m0.038s
          user 0m0.001s
          sys 0m0.041s


          If you would like to adapt this technique to also check for folders missing from dir1 but present in dir2, use rsync's --delete option:



          $ rmdir dir1/dir-0479/
          $ time rsync -nav --delete dir1/ dir2/ | grep '/$' | grep -Fvx './'
          deleting dir-0479/
          dir-0749/


          The deleting ... line tells you that dir-0479 is absent from dir1 but present in dir2.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 6 hours ago









          Jim L.Jim L.

          8262 silver badges5 bronze badges




          8262 silver badges5 bronze badges























              1














              Try either
              ls dir1 > file1; ls dir2 > file2; diff file1 file2



              or if you have vimdiff and tree which is the most useful way with sub directories, you could use



              tree dir1 > file1; tree dir2 > fiel2; vimdiff file1 file2



              Though, running ls is much faster than tree which is what you are after.



              If the difference is in a sub-directory in dir1
              eg.



              dir1
              - dir2
              - dir3
              - dir4
              vs

              dir2
              - dir2
              - dir3


              You would need to do



              ls -R dir1 > file1; ls -R dir2 > file2; vimdiff file1 file2






              share|improve this answer










              New contributor



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























                1














                Try either
                ls dir1 > file1; ls dir2 > file2; diff file1 file2



                or if you have vimdiff and tree which is the most useful way with sub directories, you could use



                tree dir1 > file1; tree dir2 > fiel2; vimdiff file1 file2



                Though, running ls is much faster than tree which is what you are after.



                If the difference is in a sub-directory in dir1
                eg.



                dir1
                - dir2
                - dir3
                - dir4
                vs

                dir2
                - dir2
                - dir3


                You would need to do



                ls -R dir1 > file1; ls -R dir2 > file2; vimdiff file1 file2






                share|improve this answer










                New contributor



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





















                  1












                  1








                  1







                  Try either
                  ls dir1 > file1; ls dir2 > file2; diff file1 file2



                  or if you have vimdiff and tree which is the most useful way with sub directories, you could use



                  tree dir1 > file1; tree dir2 > fiel2; vimdiff file1 file2



                  Though, running ls is much faster than tree which is what you are after.



                  If the difference is in a sub-directory in dir1
                  eg.



                  dir1
                  - dir2
                  - dir3
                  - dir4
                  vs

                  dir2
                  - dir2
                  - dir3


                  You would need to do



                  ls -R dir1 > file1; ls -R dir2 > file2; vimdiff file1 file2






                  share|improve this answer










                  New contributor



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









                  Try either
                  ls dir1 > file1; ls dir2 > file2; diff file1 file2



                  or if you have vimdiff and tree which is the most useful way with sub directories, you could use



                  tree dir1 > file1; tree dir2 > fiel2; vimdiff file1 file2



                  Though, running ls is much faster than tree which is what you are after.



                  If the difference is in a sub-directory in dir1
                  eg.



                  dir1
                  - dir2
                  - dir3
                  - dir4
                  vs

                  dir2
                  - dir2
                  - dir3


                  You would need to do



                  ls -R dir1 > file1; ls -R dir2 > file2; vimdiff file1 file2







                  share|improve this answer










                  New contributor



                  T. Roche 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 answer



                  share|improve this answer








                  edited 8 hours ago





















                  New contributor



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








                  answered 8 hours ago









                  T. RocheT. Roche

                  112 bronze badges




                  112 bronze badges




                  New contributor



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




                  New contributor




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























                      1














                      diff -u <(ls dir1) <(ls dir2)


                      This will make sure diff does not look inside the subdirs.



                      Or try this if you are brave ;)



                      diff -u <(find dir1/ -maxdepth 1 -type d -exec basename ;) <(find dir2/ -maxdepth 1 -type d -exec basename ;)





                      share|improve this answer

























                      • diff -u <(cd dir1; find -type d | sort) <(cd dir2; find -type d | sort) ?

                        – Hannu
                        8 hours ago






                      • 1





                        =) ............

                        – Hannu
                        8 hours ago











                      • comm -23 <(ls /dir1 |sort) <(ls /dir2 |sort) also worked for me and was very fast too

                        – Freedo
                        7 hours ago















                      1














                      diff -u <(ls dir1) <(ls dir2)


                      This will make sure diff does not look inside the subdirs.



                      Or try this if you are brave ;)



                      diff -u <(find dir1/ -maxdepth 1 -type d -exec basename ;) <(find dir2/ -maxdepth 1 -type d -exec basename ;)





                      share|improve this answer

























                      • diff -u <(cd dir1; find -type d | sort) <(cd dir2; find -type d | sort) ?

                        – Hannu
                        8 hours ago






                      • 1





                        =) ............

                        – Hannu
                        8 hours ago











                      • comm -23 <(ls /dir1 |sort) <(ls /dir2 |sort) also worked for me and was very fast too

                        – Freedo
                        7 hours ago













                      1












                      1








                      1







                      diff -u <(ls dir1) <(ls dir2)


                      This will make sure diff does not look inside the subdirs.



                      Or try this if you are brave ;)



                      diff -u <(find dir1/ -maxdepth 1 -type d -exec basename ;) <(find dir2/ -maxdepth 1 -type d -exec basename ;)





                      share|improve this answer















                      diff -u <(ls dir1) <(ls dir2)


                      This will make sure diff does not look inside the subdirs.



                      Or try this if you are brave ;)



                      diff -u <(find dir1/ -maxdepth 1 -type d -exec basename ;) <(find dir2/ -maxdepth 1 -type d -exec basename ;)






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited 8 hours ago

























                      answered 8 hours ago









                      GMasterGMaster

                      1,9451 gold badge13 silver badges21 bronze badges




                      1,9451 gold badge13 silver badges21 bronze badges












                      • diff -u <(cd dir1; find -type d | sort) <(cd dir2; find -type d | sort) ?

                        – Hannu
                        8 hours ago






                      • 1





                        =) ............

                        – Hannu
                        8 hours ago











                      • comm -23 <(ls /dir1 |sort) <(ls /dir2 |sort) also worked for me and was very fast too

                        – Freedo
                        7 hours ago

















                      • diff -u <(cd dir1; find -type d | sort) <(cd dir2; find -type d | sort) ?

                        – Hannu
                        8 hours ago






                      • 1





                        =) ............

                        – Hannu
                        8 hours ago











                      • comm -23 <(ls /dir1 |sort) <(ls /dir2 |sort) also worked for me and was very fast too

                        – Freedo
                        7 hours ago
















                      diff -u <(cd dir1; find -type d | sort) <(cd dir2; find -type d | sort) ?

                      – Hannu
                      8 hours ago





                      diff -u <(cd dir1; find -type d | sort) <(cd dir2; find -type d | sort) ?

                      – Hannu
                      8 hours ago




                      1




                      1





                      =) ............

                      – Hannu
                      8 hours ago





                      =) ............

                      – Hannu
                      8 hours ago













                      comm -23 <(ls /dir1 |sort) <(ls /dir2 |sort) also worked for me and was very fast too

                      – Freedo
                      7 hours ago





                      comm -23 <(ls /dir1 |sort) <(ls /dir2 |sort) also worked for me and was very fast too

                      – Freedo
                      7 hours ago

















                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f528988%2fhow-to-compare-the-ls-output-of-two-folders-to-find-a-missing-directory%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                      Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                      199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單