Sunday, May 5, 2024
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 444  / 3 Years ago, wed, october 20, 2021, 9:08:13

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) .



enter image description here



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...


More From » command-line

 Answers
1

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"
"}'
}


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


[#14715] Wednesday, October 20, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
trousransla

Total Points: 285
Total Questions: 112
Total Answers: 113

Location: Spain
Member since Thu, Dec 23, 2021
2 Years ago
;