Browse Ubuntu apps from command-line
I can browse Ubuntu Softwares in Gnome-Software. And they are catagorised very well . I am looking for a CLI version of this. That is, I would like to browse apps from terminal where I could list all apps under a specific category (say games) .
Why am I looking for this ?
If I could could browse apps from terminal, The search results could be highly customized using tools like grep
, awk
etc...
There already exists command apt-cache dumpavail
which will list all available packages from all enabled repositories. Behind the scenes it actually reads from files stored in /var/lib/apt/lists/
directory (I've done strace
of the command, and that's what the output shows) . My guess would be that Gnome Software parses those very same files and organizes those into categories.
Problem is that the actual data has lines that start with Package:
for package names and Section:
to which they belong, but Section:
lines are not organized exactly the same as in Gnome Software. However, with a little bit of command line magic, we can come close to something like that. What I propose is a function
filter_sections()
{
apt-cache dumpavail | \
awk -v SEARCH="$@" '/^Package:/{ PKG=$0 }\
/Section:/ && $0~SEARCH {printf PKG" "$0"\n"}'
}
With that function we can list all packages by sections, for instance:
$ filter_sections web | head
Package: apache2 Section: web
Package: awstats Section: web
Package: curl Section: web
Package: heat-api Section: web
Package: heat-api-cfn Section: web
Package: heat-api-cloudwatch Section: web
Package: heat-common Section: web
Package: heat-engine Section: web
Package: javascript-common Section: web
Package: libapache2-mod-apparmor Section: web
The code itself is fairly simple: we pass on the output of apt-cache dumpavail
to awk
which stores every package name into a varialbe , and if the Section:
line also contains a string that we are matching, we will print both package name and the section.
As for listing the sections themselves, it's fairly easy as well
apt-cache dumpavail | awk '/Section:/' | sort | uniq
What is also nice about this approach is that some of the Sections
mention which repository the package belongs to, for example universe/python
or multiverse/web
. The function , however, will search for all and of them , but if so desired we can always filter with awk
even more
You are probably looking for aptitude
.
If this is not installed in your system, go ahead and open a terminal and type
sudo apt-get install aptitude
then sudo aptitude
to start it.
If you want to search and filter results with grep
, you can use either sudo apt-cache search
or sudo aptitude search