1

I have some package installed on a computer. I want to install similar packages for other computer.

I can list down all recent packages with this command

cat /var/log/dpkg.log | grep "\ install\ "

It will output something like

2015-02-18 19:33:46 install login:amd64 <none> 1:4.1.5.1-1ubuntu9
2015-02-18 19:33:46 install lsb-base:all <none> 4.1+Debian11ubuntu6
2015-02-18 19:33:46 install makedev:all <none> 2.3.1-93ubuntu1
2015-02-18 19:33:46 install module-init-tools:all <none> 15-0ubuntu6
2015-02-18 19:33:46 install mount:amd64 <none> 2.20.1-5.1ubuntu20
2015-02-18 19:33:46 install mountall:amd64 <none> 2.53

This list is quite big.

I want to make it something like

sudo apt-get install login lsb-base module-init-tools mount mountall

3 Answers3

2

You don't need to make it as you wish, there is a better way of backing up a list of programs:

On the First compute run those commands:

dpkg --get-selections > /some-path/packages.list

sudo cp -R /etc/apt/sources.list* /some-path/

sudo apt-key exportall > /some-path/Repo.keys

Then copy those files to the other computer and there run those commands to install exactly the same apps from the first computer:

sudo apt-key add /some-path/Repo.keys

sudo cp -R /some-path/sources.list* /etc/apt/

sudo apt-get update

sudo apt-get install dselect

sudo dpkg --set-selections < /some-path/packages.list

sudo apt-get dselect-upgrade -y
Maythux
  • 87,123
1

command to do this is

cat /var/log/apt/history.log | grep "\ install\ " | awk '/ install / {printf "%s ",$4 }'
1

Save all the installed packages shown by /var/log/dpkg.log in an array:

mapfile -t packages < <(grep -Po '.* install \K[^ ]+' /var/log/dpkg.log)

Here the array packages will contain all the package names.

Now you can simple do:

echo "${packages[@]}"

to see the package names in a space separated form.

This will work well with apt-get command:

sudo apt-get install --dry-run "${packages[@]}"

The above command will be expanded to:

sudo apt-get install --dry-run libntlm0:amd64 libgsasl7:amd64 ....

If you have ssh access from the new computer to the one where the package are installed, from NEW computer you can use:

$ mapfile -t packages < <(ssh OLD 'grep -Po ".* install \K[^ ]+" /var/log/dpkg.log'))"

This will save the package names from OLD computer in the array packages. change the ssh parameters accordingly.

Now you can simply do:

$ sudo apt-get install "${packages[@]}"
heemayl
  • 93,925