0

I recently destroyed the system partition on my Ubuntu 14.04 machine. I hadn't bothered to back it up since I knew I could easily restore it from a DVD. The problem is that every once in a while I come across a package that I need that I don't have. Of course, I can install it easily with apt-get, but that interrupts my work flow.

It's too late for this machine, of course, but in the future, I would like to have a list of all the packages installed on the machine. Then I could do something clever like

xargs < file_with_list_of_pckgs | apt-get install

Then periodically, I can create a list of packages. If I ever zap the system partition again, I can install Ubuntu from DVD and then use apt-get to get the packages I am missing.

I also have to backup everything under /etc.

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
Jeff Silverman
  • 692
  • 1
  • 8
  • 15

1 Answers1

2

This is a one-liner which will generate such a list on a single line.

dpkg -l | awk  '{print $2}' > package_list.txt

The package_list.txt file may have a few weird lines at the top, which are easy to get rid of using your favorite text editor. You can then install all of the modules you need with

xargs < package_list.txt apt-get install -y

Unfortunately, you need the -y switch because xargs redirects stdin, so you are going to install all of the packages in the package_list.txt that are out of date. However, you probably want to do that anyway or else you wouldn't try this stunt.

Jeff Silverman
  • 692
  • 1
  • 8
  • 15