13

I am trying to move from one arch install a (partitioned one) to another (a less-partitioned one) on my computer and I want a similar set up. So I was wondering if there was a simple way to get pacman to install the same packages.

I was thinking of something like

pacman -Qe | awk '{print $1}' > package_list.txt

then creating a script to install from that list. Is there a way I can create that script in a few comands; if not, how should I go about doing this?

3 Answers 3

21
pacman -Qqen > pkglist.txt

To install:

pacman -S - < pkglist.txt

From ArchWiki: https://wiki.archlinux.org/index.php/Pacman/Tips_and_tricks#List_of_installed_packages

3
  • Seriously, a loop?
    – Tom Yan
    Commented Apr 5, 2016 at 14:46
  • 1
    @TomYan is this better? "pacman -S $(< package.list.txt)"
    – user577582
    Commented Apr 5, 2016 at 17:00
  • Why not just quote the (decent) commands from the ArchWiki? Edited.
    – Tom Yan
    Commented Apr 5, 2016 at 17:36
2

I know this is old but I wish to propose a more comprehensive solution.

The way I do it utilises the same idea and proposed in archlinux.org site.

  • First you need the list of packages, this can be done with

    pacman -Qqe > pkglist.txt
    

    Here pacman -Q queries all installed programs, the -q removes version numbers and the -e is for listing the explicitly installed programs.

  • Now, when we want to restore/install the programs, I prefer doing

    installable_packages=$(comm -12 <(pacman -Slq | sort) <(sort pkglist.txt))
    pacman -S --needed $installable_packages
    

    Here we only get the packages from the list are available from pacman. That is done with the comm -12 file1 file2 command. The -12 flag suppresses unique lines in file 1 and 2 and leaves us with the intersection of the two files; i.e., the installable packages.

0

Example in case some of you wanna do it without an intermediate file:

# Method description: 
# For each parameter passed,
# offer to remove all packages containing that string,
# with all its dependencies.
pacman_purge() {  
  for var in "$@"do
     # Command explanation: 
     # By passing - to pacman at the end of the line,
     # we tell it to read stdin.
     # That way we don't need awk or xargs.
     #
     # Rs --unneeded will remove only where don't break dependencies 
     # (instead of exiting with errors, as by default).

     pacman -Qeq | grep "$var" | sudo pacman -Rs - --unneeded
  done
}

# Optional
alias pacman-purgue='pacman_purge'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .