In a previous post, I talked about Chocolatey on Windows. That is a package manager where you can install all your typical, small applications at-once. Instead of manually running an .msi and clicking next, next, finish – you can run “choco install packagename”. For me, I have a list of apps in my OneNote, so that whenever I need to rebuild my Windows workstation, I can easily re-install all of those small applications that I use, but easily forget about. I have a list of “choco install” statements so that on a fresh install I can kick them off, wait about :15 minutes and then almost all of my applications are installed.
Meanwhile, on my Linux workstation, I’ve installed several little utilities and was thinking “Oh no! I should’ve written this down, I’m not going to remember the name of these!” So as I’ve been “moving in” to Linux and installing little utilities to solve little problems, I haven’t been writing them down. This means whenever I go to rebuild this workstation at some point, I’m going to have to re-find all of these utilities. There must be a better way!
Then I realized: “Wait a second, I’m on Linux: there must be a log file!” In particular, I’m using Ubuntu which is based on Debian Linux. Debian uses “apt-get”, or “Advanced Package Tool (APT)” as a package manager to install applications. Since “apt-get” from the command line AND from the Ubuntu Software Center all install software the same they, they all write messages to /var/log/dpkg.log (the log file used by APT for ALL package installs/uninstalls/upgrades), there is a record of everything I’ve ever installed!
So, to get a list of all of the programs I installed, I built this command:
$ grep "status installed" /var/log/dpkg.log | grep -v " lib"
Grep lets you find the specified text in the specified file. So, I just pull all of the lines from the /var/log/dpkg.log file that have the words “status installed” on them. We “pipe” | the output into the next grep command to exclude lines that have ” lib” (-v means to exclude that matching text), because those are just library dependencies. When you call grep without a filename, it will look at the “standard input” for data to be piped to it. So in this case, we are calling grep, and piping that output to another grep statement.
The result is a pretty good list of products I’ve explicitly installed – but it also has dependencies which I didn’t explicitly install. So, it’s a big list, but not unmanageable. The format is something like this:
2015-08-26 00:35:21 status installed gimp-data:all 2.8.14-1ubuntu1 2015-08-26 00:35:21 status installed python-gtk2:amd64 2.24.0-3ubuntu4 2015-08-26 00:35:21 status installed gimp:amd64 2.8.14-1ubuntu1 2015-08-26 00:36:01 status installed man-db:amd64 22.214.171.124-5 2015-08-26 00:36:01 status installed gnome-menus:amd64 3.10.1-0ubuntu5 2015-08-26 00:36:01 status installed desktop-file-utils:amd64 0.22-1ubuntu3
Like I said, many of these are dependencies so, the last step would be to go through the list and write down in OneNote all of the programs I am using (and which I explicitly installed). Then, if I ever need to rebuild this workstation, I would have this massive “sudo apt-get install package1 package2 package3 …” statement and I’d be back up and running.I thought that was pretty cool and wanted to write it down, mostly for Future Robert.
UPDATE: After writing this, I also ended up finding /var/log/apt/history.log which has all of my actual “apt-get” commands. So, no filtering required, I can go see every installation command I’ve submitted! To make it readable – I can pull out just the date and the command line with grep:
grep "Start-Date:|Commandline: apt-get install " /var/log/apt/history.log
and that gives me output like this:
Start-Date: 2015-08-27 02:27:24 Commandline: apt-get install readpst Start-Date: 2015-08-27 11:03:54 Commandline: apt-get install steghide Start-Date: 2015-08-27 11:30:37 Commandline: apt-get install john Start-Date: 2015-08-27 11:32:40 Commandline: apt-get install crunch Start-Date: 2015-08-27 13:31:44 Commandline: apt-get install git Start-Date: 2015-08-27 13:43:44 Commandline: apt-get install stegdetect
So there you go! I just need to write down the ones I want to keep (the ones I would want to re-run on a future build), and I have a rebuildable workstation, in terms of installed software.