How to list ALL installed packages on Ubuntu Linux

What command I need to type in my shell script to list all installed packages on Ubuntu Linux server? I need to create a new list for backup purposes.

We list installed packages with apt, apt-get, and dpkg commands:

  1. To list installed packages with apt on Ubuntu:
    sudo apt list --installed
  2. Filter out package and search for for atop using grep on Ubuntu:
    sudo apt list --installed | grep atop
    sudo apt list --installed | grep -E -i 'atop|htop|vtop|apache2'
  3. Counting the number of packages installed on your Ubuntu Linux server using wc -l:
    sudo apt list --installed | wc -l
  4. The packages list is always long, hence we use more or less:
    sudo apt list --installed | more
    sudo apt list --installed | less
  5. Listing installed packages with dpkg-query command possible too:
    sudo dpkg-query -l | less
  6. Creating a list of all installed packages on Ubuntu is simple (make sure you copy apt-backups.txt file somewhere else):
    sudo dpkg-query -f '${binary:Package}\n' -W > apt-backups.txt
  7. Want to restore that backup? It is easy:
    sudo xargs -a apt-backups.txt apt install

Check out apt man pages: Ubuntu Manpage: apt - command-line interface and Ubuntu Manpage: dpkg-query - a tool to query the dpkg database

1 Like

very useful @monk <3


Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki