How to list all installed packages from a specific category (component)











up vote
4
down vote

favorite
1












Is it possible to list all installed packages from a specific official repository component (Main, Restricted, Universe or Multiverse) using utilities like apt, apt-cache, aptitude?



I wrote a simple script for this purpose:



dpkg -l | grep ^ii | cut -f3 -d ' ' | while read -r pkg;
do
status=`apt-cache show $pkg | grep -m1 "Section: multiverse"`
if [ ! -z "$status" ]
then
echo $pkg
fi
done;


It works, but it's really slow cause it's checking all packages one by one. Running the time command for this script will produce:



real    1m16.797s
user 0m57.008s
sys 0m8.260s


I already tried aptitude search patterns, and dpkg-query formating, but it seems they don't have the proper column/schema to create a query for this purpose.



I also had a look at vrms script to find out how it's works, because it's really fast in finding contrib/non-free packages, it's seems that vrms script scans the whole /var/lib/dpkg/status file, looking for things like 'Section: (contrib | non-free | restricted | multiverse | partner )', so it wasn't helpful either, because not all packages have this section.










share|improve this question




























    up vote
    4
    down vote

    favorite
    1












    Is it possible to list all installed packages from a specific official repository component (Main, Restricted, Universe or Multiverse) using utilities like apt, apt-cache, aptitude?



    I wrote a simple script for this purpose:



    dpkg -l | grep ^ii | cut -f3 -d ' ' | while read -r pkg;
    do
    status=`apt-cache show $pkg | grep -m1 "Section: multiverse"`
    if [ ! -z "$status" ]
    then
    echo $pkg
    fi
    done;


    It works, but it's really slow cause it's checking all packages one by one. Running the time command for this script will produce:



    real    1m16.797s
    user 0m57.008s
    sys 0m8.260s


    I already tried aptitude search patterns, and dpkg-query formating, but it seems they don't have the proper column/schema to create a query for this purpose.



    I also had a look at vrms script to find out how it's works, because it's really fast in finding contrib/non-free packages, it's seems that vrms script scans the whole /var/lib/dpkg/status file, looking for things like 'Section: (contrib | non-free | restricted | multiverse | partner )', so it wasn't helpful either, because not all packages have this section.










    share|improve this question


























      up vote
      4
      down vote

      favorite
      1









      up vote
      4
      down vote

      favorite
      1






      1





      Is it possible to list all installed packages from a specific official repository component (Main, Restricted, Universe or Multiverse) using utilities like apt, apt-cache, aptitude?



      I wrote a simple script for this purpose:



      dpkg -l | grep ^ii | cut -f3 -d ' ' | while read -r pkg;
      do
      status=`apt-cache show $pkg | grep -m1 "Section: multiverse"`
      if [ ! -z "$status" ]
      then
      echo $pkg
      fi
      done;


      It works, but it's really slow cause it's checking all packages one by one. Running the time command for this script will produce:



      real    1m16.797s
      user 0m57.008s
      sys 0m8.260s


      I already tried aptitude search patterns, and dpkg-query formating, but it seems they don't have the proper column/schema to create a query for this purpose.



      I also had a look at vrms script to find out how it's works, because it's really fast in finding contrib/non-free packages, it's seems that vrms script scans the whole /var/lib/dpkg/status file, looking for things like 'Section: (contrib | non-free | restricted | multiverse | partner )', so it wasn't helpful either, because not all packages have this section.










      share|improve this question















      Is it possible to list all installed packages from a specific official repository component (Main, Restricted, Universe or Multiverse) using utilities like apt, apt-cache, aptitude?



      I wrote a simple script for this purpose:



      dpkg -l | grep ^ii | cut -f3 -d ' ' | while read -r pkg;
      do
      status=`apt-cache show $pkg | grep -m1 "Section: multiverse"`
      if [ ! -z "$status" ]
      then
      echo $pkg
      fi
      done;


      It works, but it's really slow cause it's checking all packages one by one. Running the time command for this script will produce:



      real    1m16.797s
      user 0m57.008s
      sys 0m8.260s


      I already tried aptitude search patterns, and dpkg-query formating, but it seems they don't have the proper column/schema to create a query for this purpose.



      I also had a look at vrms script to find out how it's works, because it's really fast in finding contrib/non-free packages, it's seems that vrms script scans the whole /var/lib/dpkg/status file, looking for things like 'Section: (contrib | non-free | restricted | multiverse | partner )', so it wasn't helpful either, because not all packages have this section.







      command-line apt package-management dpkg aptitude






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 at 17:48









      Zanna

      49.1k13123234




      49.1k13123234










      asked Mar 31 '17 at 21:25









      Ravexina

      30.6k1478106




      30.6k1478106






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          Okay, I didn't found any solution to do this with standard utilities, however after having a look at vrms I came-up with a pretty better script to search for packages installed from a specific component.



          The other script which I mentioned in my question was really time consuming.

          However, the new script is available here: pkgs-from.sh



          The usage is:



          ./pkgs-from.sh universe # or main, multiverse, backports


          And the time command result for this one is:



          real    0m4.367s
          user 0m0.980s
          sys 0m0.408s


          Which is pretty good.



          How it works?

          The script will create a list of all packages related to the requested component from related files within the /var/lib/apt/lists/ directory, then starts to search throughout them instead of using apt-cache.






          share|improve this answer





















            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
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f898980%2fhow-to-list-all-installed-packages-from-a-specific-category-component%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote













            Okay, I didn't found any solution to do this with standard utilities, however after having a look at vrms I came-up with a pretty better script to search for packages installed from a specific component.



            The other script which I mentioned in my question was really time consuming.

            However, the new script is available here: pkgs-from.sh



            The usage is:



            ./pkgs-from.sh universe # or main, multiverse, backports


            And the time command result for this one is:



            real    0m4.367s
            user 0m0.980s
            sys 0m0.408s


            Which is pretty good.



            How it works?

            The script will create a list of all packages related to the requested component from related files within the /var/lib/apt/lists/ directory, then starts to search throughout them instead of using apt-cache.






            share|improve this answer

























              up vote
              1
              down vote













              Okay, I didn't found any solution to do this with standard utilities, however after having a look at vrms I came-up with a pretty better script to search for packages installed from a specific component.



              The other script which I mentioned in my question was really time consuming.

              However, the new script is available here: pkgs-from.sh



              The usage is:



              ./pkgs-from.sh universe # or main, multiverse, backports


              And the time command result for this one is:



              real    0m4.367s
              user 0m0.980s
              sys 0m0.408s


              Which is pretty good.



              How it works?

              The script will create a list of all packages related to the requested component from related files within the /var/lib/apt/lists/ directory, then starts to search throughout them instead of using apt-cache.






              share|improve this answer























                up vote
                1
                down vote










                up vote
                1
                down vote









                Okay, I didn't found any solution to do this with standard utilities, however after having a look at vrms I came-up with a pretty better script to search for packages installed from a specific component.



                The other script which I mentioned in my question was really time consuming.

                However, the new script is available here: pkgs-from.sh



                The usage is:



                ./pkgs-from.sh universe # or main, multiverse, backports


                And the time command result for this one is:



                real    0m4.367s
                user 0m0.980s
                sys 0m0.408s


                Which is pretty good.



                How it works?

                The script will create a list of all packages related to the requested component from related files within the /var/lib/apt/lists/ directory, then starts to search throughout them instead of using apt-cache.






                share|improve this answer












                Okay, I didn't found any solution to do this with standard utilities, however after having a look at vrms I came-up with a pretty better script to search for packages installed from a specific component.



                The other script which I mentioned in my question was really time consuming.

                However, the new script is available here: pkgs-from.sh



                The usage is:



                ./pkgs-from.sh universe # or main, multiverse, backports


                And the time command result for this one is:



                real    0m4.367s
                user 0m0.980s
                sys 0m0.408s


                Which is pretty good.



                How it works?

                The script will create a list of all packages related to the requested component from related files within the /var/lib/apt/lists/ directory, then starts to search throughout them instead of using apt-cache.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Apr 4 '17 at 13:22









                Ravexina

                30.6k1478106




                30.6k1478106






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f898980%2fhow-to-list-all-installed-packages-from-a-specific-category-component%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

                    How to send String Array data to Server using php in android

                    Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

                    Is anime1.com a legal site for watching anime?