Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Greetings again. I am about do move a server from one Ubuntu box to another. I'm not cloning the old box to the new; I'm creating a new system and will move data as needed. I want to install all the software that I have on the old box on the new one.

Is there a simple way to find the history of all the "sudo apt-get install" commands I have given over time? That is, dpkg -l shows me all the packages that have been installed, but not which top-level package installed them. If there is a way for dpkg to give me the installing package, I can find the unique ones there; otherwise, I want something else to say "you installed these 24 packages".

share|improve this question
2  

5 Answers 5

The apt history is in /var/log/apt/history.log as said in a comment above. That said, this will not list packages that were installed manually, using dpkg or GUIs such as gdebi. To see all the packages that went through dpkg, you can look at /var/log/dpkg.log.

share|improve this answer

http://www.debianadmin.com/clone-your-ubuntu-installation.html

and /var/adm/apt/history.log

share|improve this answer
5  
The procedure in the first link doesn't distinguish between automatically-installed packages and manually-installed packages. /var/log/apt/history.log (you got the location wrong btw) will have rotated away after a few months. –  Gilles Aug 28 '10 at 7:55
    
Gilles is right on both counts. I only have about of month's worth of those logs, and I can't even see how the log deletion rate is set (it's done with 'newsyslog' on FreeBSD). So I still don't have a solution, but I have some pointers. I can at least grep the output from the command in the cloning article, look for "high-level" names, install them on the new one, do the same thing on the new box, diff the two results, and repeat until satisfied. I would still ove to hear more ideas. –  Paul Hoffman Aug 29 '10 at 15:42

I thought there was an apt command for this, but I can't find it, so here's a manual way.

The following command gives the list of packages whose installation was requested, whether manually or automatically. Unless you're in the middle of (de)installing packages, this is the list of installed packages.

dpkg --get-selections | sed -n 's/\t\+install$//p'

The following command gives a superset of automatically installed packages:

</var/lib/apt/extended_states awk -v RS= '/\nAuto-Installed: *1/{print$2}'

Putting it all together, the following command lists manually installed packages:

comm -23 <(dpkg --get-selections | sed -n 's/\t\+install$//p') \
         <(</var/lib/apt/extended_states \
           awk -v RS= '/\nAuto-Installed: *1/{print$2}' |sort)
share|improve this answer

To get the list of most recent installed packages in descending order, I like using (e.g. 25 lines):

tac /var/log/apt/history.log |head --lines=25
share|improve this answer

Instead of tac / head combination, it is better to use tail (for last 25 lines):

tail -n 25 /var/log/apt/history.log
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.