Question: What does the `apt-get install ...` command do?

When I enter `apt-get install ...` command, there are some texts appearing on the screen, but that does not have enough information for me. I want to know if any file is created / edited, any service is started and other activities...

Is there any `.sh` file executed when the `apt-get install ...` run? If so, how can I see the content of that `sh` file?

The reason for this question is recently I tried to install tomcat7 with `apt-get install tomcat7`. Everything works fine until I install `tomcat7-admin` (manager web application), the server became unresponsive to any request. I tried this many times, and this always happen.

Answer: 
For the actual *under-the-hood* stuff, you'll need to grab the Apt source. Fairly simple if you have source repositories enabled:

```
apt-get source apt

```

The `apt-get` command itself lives in `cmdline/apt-get.cc`. It's a pain to read through but most of `apt-get`'s actions are spelled out quite extensively in there. Installation however, is mapped through a `DoInstall` function which lives in `apt-private/private-install.{cc,h}`.

You have to remember that apt-get is merely one side of the coin.  

`dpkg` is handling the actual installation but `DoInstall` doesn't know about `dpkg` directly. `apt-get` is actually surprisingly package-manager agnostic. All the functionality is abstracted through `apt-pkg/package-manager.cc`

I'm only looking briefly but even there I can't see where this actually attaches to the `dpkg` systems. Some of this seems to be autoconfigured through `apt-pkg/aptconfiguration.cc` but this is a deep well. You could spend days unravelling this.

The source documentation is good though. You could do worse things than to go through each file and read the header to work out what's actually happening.
There are some fantastic answers here which are better than this short one, but something you might consider to help you get a better understanding of the changes made by a package manager is [Docker](https://www.docker.com). You can diff the changes made in a container using `docker diff <container>` and it will show you all of the changes. This is especially useful for taking a look under the hood to see what `apt-get install` does to a system. A quick search will get you [several](http://www.scriptrock.com/blog/comparing-containers-generating-dockerfiles-guardrail) [resources](https://stackoverflow.com/questions/21200304/docker-how-to-show-the-diffs-between-2-images) to help implement this.