Score:0

How can I list my installed snaps together with their track/risk/branch?

us flag

Context

I would like to list the installed snaps on my machine, together with their channel information (<track>/<risk>/<branch>). My intention is to store that data in a file, so that I can somehow reinstall the same snaps on a new system.

Issue

The built-in command snap list seems to be geared towards printing data to a human being, and to not have options to tweak its output to have a complete dump of some fields.

So I have a nice display ("nice" as in "pleasant to the eye") :

$ snap list
Name                            Version                     Rev    Tracking         Publisher       Notes
firefox                         106.0.5-1                   2067   latest/stable    mozilla✓        -
snap-store                      41.3-64-g512c0ff            599    latest/stable/…  canonical✓      -
...

but I don't know how to restrict this to, say, Name / Tracking (note: I know that part is just a awk '{ print $1, $4 }' one liner), or how to have the complete track specification rather than in snap-store ... latest/stable/….

I also tried looking around for where snap stores its configuration files (e.g: the ones that say: firefox should be updated from latest/stable), but I could not find config directory /etc/snap<something>, I had no luck looking at man snap or snap help *.

I started looking at dpkg -L snap to have a view of what directories/files could possibly be involved with snap, but I figured I would better ask rather than start reverse engineering on my own.

My Question

How can I get a list of installed snaps on my system, together with the detailed track information ?

Bonus if I can get this using only snap commands, but using common cli tools (find, awk, grep, jq ...) to get this from plain files on disk is acceptable too.


extra info :

$ snap --version
snap    2.57.5+22.04
snapd   2.57.5+22.04
series  16
ubuntu  22.04
kernel  5.15.0-52-generic
Score:1
pl flag

As you have discovered the snap command is limited in how the output is formatted. You can get a full list of every snap with all the information using --verbose.

 for f in $(snap list| tail -n +2 | awk '{print $1}'); do snap info --verbose $f; done

This will print every snap installed with all channel information.

Score:0
us flag

Building on @popey's answer, here is the script I wrote to list my installed snaps :

for f in $(snap list| tail -n +2 | awk '{print $1}'); do
    snap info $snap |\
      grep -E -e "^(name|tracking):" |\
      awk '{ if (name) { print name"\t"$2; } name=$2 }'
done

# sample output:
# bare  latest/stable
# btop  latest/stable
# chromium  latest/stable
# gtk-common-themes latest/stable/ubuntu-22.04

It looks like snap takes forever to run snap info, here is one way to run this in parallel :

#!/bin/bash

get_snap_info () {
    local snap=$1
    snap info $snap |\
      grep -E -e "^(name|tracking):" |\
      awk '{ if (name) { print name"\t"$2; } name=$2 }'
}

export -f get_snap_info

snap list| tail -n +2 | awk '{print $1}' | parallel --keep-order get_snap_info
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.