Score:2

Install Snap from a list file

ad flag

I can get a list of installed snaps, but what if I have a new laptop, and need to install all snaps listed by snap list?

Score:5
my flag

and need to install all snaps listed by snap list?

So you are using the snap list command to list all the snap packages. When we call snap list it prints many rows and columns (similar to dpkg -l), for example on my machine:

$ snap list
Name               Version             Rev    Tracking         Publisher   Notes
bare               1.0                 5      latest/stable    canonical*  base
core18             20211215            2284   latest/stable    canonical*  base
core20             20220114            1328   latest/stable    canonical*  base
gnome-3-34-1804    0+git.3556cb3       77     latest/stable/…  canonical*  -
gnome-3-38-2004    0+git.1f9014a       99     latest/stable    canonical*  -
gtk-common-themes  0.1-59-g7bca6ae     1519   latest/stable/…  canonical*  -
snap-store         3.38.0-66-gbd5b8f7  558    latest/stable/…  canonical*  -
snapd              2.54.3              14978  latest/stable    canonical*  snapd

So, you can't simply run sudo snap install $(cat snap-list.txt).

You need to use the awk utility to print only the names of the packages.

  1. Run snap list > snap-list on the machine you have installed all your snap packages.

  2. Transfer the snap-list file to your new laptop.

  3. Open a terminal and cd into the directory containing the snap-list file.

  4. Run the following command:

    awk -F "\t" 'NR>1 {print $1}' snap-list | xargs sudo snap install
    
Score:1
gb flag

Run:

cut -d ' ' -f 1 snap-list | grep -v Name | xargs -n 1 sudo snap install

This

  • takes the first column from the snap-list file (delimited by spaces),
  • discards "Name" as it's just a heading,
  • and runs sudo snap install for each row
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.