Sum the installed sizes of packages matching a substring

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











up vote
3
down vote

favorite












I would like to get all the packages that contain the "nvidia" substring in their name, to sum up their size and print the total size in megabytes.
To do so I have written the following oneliner:



dpkg-query -Wf '$Installed-Sizet$Packagen' | sort -n | grep nvidia | awk -F' ' 'sum+=$1ENDprint sum/1024;'


But, how can I beautify it, make it as short as it is possible to be, keeping the functionality?



It is crooked-written for now, as you can see.










share|improve this question









New contributor




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























    up vote
    3
    down vote

    favorite












    I would like to get all the packages that contain the "nvidia" substring in their name, to sum up their size and print the total size in megabytes.
    To do so I have written the following oneliner:



    dpkg-query -Wf '$Installed-Sizet$Packagen' | sort -n | grep nvidia | awk -F' ' 'sum+=$1ENDprint sum/1024;'


    But, how can I beautify it, make it as short as it is possible to be, keeping the functionality?



    It is crooked-written for now, as you can see.










    share|improve this question









    New contributor




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





















      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I would like to get all the packages that contain the "nvidia" substring in their name, to sum up their size and print the total size in megabytes.
      To do so I have written the following oneliner:



      dpkg-query -Wf '$Installed-Sizet$Packagen' | sort -n | grep nvidia | awk -F' ' 'sum+=$1ENDprint sum/1024;'


      But, how can I beautify it, make it as short as it is possible to be, keeping the functionality?



      It is crooked-written for now, as you can see.










      share|improve this question









      New contributor




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











      I would like to get all the packages that contain the "nvidia" substring in their name, to sum up their size and print the total size in megabytes.
      To do so I have written the following oneliner:



      dpkg-query -Wf '$Installed-Sizet$Packagen' | sort -n | grep nvidia | awk -F' ' 'sum+=$1ENDprint sum/1024;'


      But, how can I beautify it, make it as short as it is possible to be, keeping the functionality?



      It is crooked-written for now, as you can see.







      debian awk grep






      share|improve this question









      New contributor




      Twissell 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




      Twissell 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 4 hours ago









      Goro

      5,67552460




      5,67552460






      New contributor




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









      asked 4 hours ago









      Twissell

      183




      183




      New contributor




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





      New contributor





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






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




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          You can filter using dpkg-query itself, which means you don’t need to output the package name, and you don’t need to sort either:



          dpkg-query -Wf '$Installed-Sizen' '*nvidia*' | awk 'sum+=$1ENDprint sum/1024;'





          share|improve this answer




















            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',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );






            Twissell 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%2funix.stackexchange.com%2fquestions%2f472550%2fsum-the-installed-sizes-of-packages-matching-a-substring%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            4
            down vote



            accepted










            You can filter using dpkg-query itself, which means you don’t need to output the package name, and you don’t need to sort either:



            dpkg-query -Wf '$Installed-Sizen' '*nvidia*' | awk 'sum+=$1ENDprint sum/1024;'





            share|improve this answer
























              up vote
              4
              down vote



              accepted










              You can filter using dpkg-query itself, which means you don’t need to output the package name, and you don’t need to sort either:



              dpkg-query -Wf '$Installed-Sizen' '*nvidia*' | awk 'sum+=$1ENDprint sum/1024;'





              share|improve this answer






















                up vote
                4
                down vote



                accepted







                up vote
                4
                down vote



                accepted






                You can filter using dpkg-query itself, which means you don’t need to output the package name, and you don’t need to sort either:



                dpkg-query -Wf '$Installed-Sizen' '*nvidia*' | awk 'sum+=$1ENDprint sum/1024;'





                share|improve this answer












                You can filter using dpkg-query itself, which means you don’t need to output the package name, and you don’t need to sort either:



                dpkg-query -Wf '$Installed-Sizen' '*nvidia*' | awk 'sum+=$1ENDprint sum/1024;'






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 4 hours ago









                Stephen Kitt

                148k22324393




                148k22324393




















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









                     

                    draft saved


                    draft discarded


















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












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











                    Twissell 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%2funix.stackexchange.com%2fquestions%2f472550%2fsum-the-installed-sizes-of-packages-matching-a-substring%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