using this command I save all the sudo apt-get install to a text file: history | grep "sudo apt-get install" | sed 's/^ *//' | cut -d' ' -f3- > ~files/packages/installed_on_raspberrypi.txt

how can I make a cron job that it should run twice a day in morning and in the end of the day ?


Use of etckeeper is a very good idea.

However, to get a list of all installed (and deinstalled) packages, you should use: dpkg --get-selections. This gives you all packages that should be installed and uninstalled on your system.

If you ever want to reinstall a system according to this list you do: dpkg --set-selections < /path/to/file and then run apt-get dselect-upgrade

If you want to see what was when installed and/or uninstalled you have the logfile: /var/log/dpkg.log

Using the history command might not reveal everything that you have installed, since it does not save a great bunch of commands, except of course you set it longer. man history gives you more information on that.


While not a text file nor using chron, you can use a combination of git and etckeeper to achieve the same result.

etckeeper allows the contents of /etc to be stored in a Version Control System (VCS) repository. It integrates with APT and automatically commits changes to /etc when packages are installed or upgraded. Placing /etc under version control is considered an industry best practice, and the goal of etckeeper is to make this process as painless as possible. - from the Ubuntu Documentation

Start by installing git:

sudo apt-get install git

Configure git for the root account:

sudo git config –global user.name “Your Name”
sudo git config –global user.email youremailaddress

Then install etckeeper:

sudo apt-get install etckeeper

Because git is already installed this will not only install etckeeper, but initialize the database and make an initial commit of the files in /etc.

You can check the status of the repository with the following commands:

cd /etc
sudo git status

you should see the following:

On branch master nothing to commit, working directory clean

Now anytime you run an apt command (install, purge etc.) Etckeeper will automatically add a commit to the underlying git repo, noting the changes and time they were made.

You can view all packages installed, updated and removed using the git log command.

cd /etc
sudo git log

As I mentioned this is not a text file, but the git log can certainly be turned into a text file if needed. This also has the advantage of being automatic and tracking any changes made manually to your systems config files.

I wrote a blog post with additional details and some config settings you may want to make available here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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