6

Is there a way to sort the results from apt-cache search <keywords>?

muru
  • 207,228
user784637
  • 11,465

2 Answers2

6

Pipe the result to sort:

apt-cache search keyword | sort

The vertical bar is called pipe. It takes the output from apt-cache and transfers it to the input of sort.

Lesmana
  • 18,754
3

You can pipe the output of apt-cache search to popsort.py (see footnotes) which sorts it in the increasing order of popularity and displays a popularity rank at the beginning.

For example, a typical apt-cache search run might look as

$ apt-cache search sqlite browser             
alice - Web browser (WebKit or Gecko) based IRC client
gtkcookie - editor for cookie files
hoteldruid - web-based property management system for hotels or B&Bs
nova-consoleauth - OpenStack Compute - Console Authenticator
ruby-http-cookie - Ruby library to handle HTTP Cookies based on RFC 6265
sqlitebrowser - GUI editor for SQLite databases

If the output is piped to popsort.py

$ apt-cache search sqlite browser | popsort.py 
66341 hoteldruid - web-based property management system for hotels or B&Bs
58787 nova-consoleauth - OpenStack Compute - Console Authenticator
43444 alice - Web browser (WebKit or Gecko) based IRC client
36506 gtkcookie - editor for cookie files
8052 ruby-http-cookie - Ruby library to handle HTTP Cookies based on RFC 6265
7114 sqlitebrowser - GUI editor for SQLite databases

which shows that sqlitebrowser, ruby-http-cookie are popular by an order of magnitude compared to others.

Footnotes

  1. popsort.py is a python script I wrote. It requires Python3. The latest version can be found here or just

    wget https://gitlab.com/d3k2mk7/rutils/raw/master/bin/popsort.py
    
  2. Latest documentation

  3. The script gets the popularity rankings from popcon.debian.org/by_inst which is good enough for Debian users. You may have to edit it accordingly for Ubuntu.
  4. I had to break the URLs since the website does not allow new users to post URLs unless they have 10 reputation points (which I do not!).
Pablo Bianchi
  • 17,371