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
6
  • You need to cut that list to get only the name of the packages, and then pass those names into the apt-get install command
    – LnxSlck
    Jun 23, 2015 at 8:44
  • Yes, i am trying to figure out a way to do that. I think awk command can do it but not sure about it. Can you direct me towards a way to do it ? Jun 23, 2015 at 8:48
  • cat /var/log/apt/history.log | grep "\ install\ "
    – LnxSlck
    Jun 23, 2015 at 9:02
  • Take a look at Alvin Row answer here askubuntu.com/questions/17012/…
    – LnxSlck
    Jun 23, 2015 at 9:02
  • thanks, but again it gives me output in several line. problem is I have 1000s of such line. I want to extract all those packages name. Jun 23, 2015 at 9:10

3 Answers 3

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
8
  • dpkg --get-selections will list all the packages in any conditions....this will show the packages that were installed automatically, manually, comes preinstalled..OP wants only the manually installed ones..
    – heemayl
    Jun 23, 2015 at 10:21
  • @heemayl yes you alright list all the packages in any conditions but I didn't see anywhere the OP asks for manually installed packages. He asked: I have some package installed on a computer. I want to install similar packages for other computer. He didn't say I installed some packages
    – Maythux
    Jun 23, 2015 at 10:25
  • OP is parsing /var/log/dpkg.log..that is the idea of it all in my opinion..
    – heemayl
    Jun 23, 2015 at 10:26
  • Mmmm Maybe you are right, wait for the OP response
    – Maythux
    Jun 23, 2015 at 10:27
  • @Maythux Thanks , I only needed manually installed packages but as both computers are freshly installed. I need all the packages on computer1 to be installed on computer2. Jun 23, 2015 at 11:39
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[@]}"
1

command to do this is

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

You must log in to answer this question.

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