Command-line equivalences of some tasks in Synaptic

I already use apt-get for most of my package management. Yet, there are times when I occasionally need to use Synaptic to do certain things. I would like to learn the equivalent commands for doing the following things in Synaptic:

  • Check a package's dependencies / dependent packages. (This can be done in Synaptic by viewing the properties of a package).
  • Browse available packages
  • Search (in package names as well as the details/descriptions) for some key. (The search function at the top of synaptic)
  • Check if a package is installed or not

Also, is there a way to find packages that are no longer necessary (e.g. a package no longer in use because I removed a dependency). I have a feeling my system is terribly bloated because I removed certain programs and not all the dependencies went with them.


Solution 1:

  • Check a package's dependencies / dependent packages. (This can be done in Synaptic by viewing the properties of a package):

    apt-cache depend 'package-name'
    apt-cache rdepend 'package-name'
    
  • Browse available packages

    apt-cache pkgnames
    apt-cache search '.*'
    apt-cache show 'package-name'
    
  • Search (in package names as well as the details/descriptions) for some key. (The search function at the top of synaptic)

    apt-cache search pattern
    apt-cache --names-only search pattern
    
  • Check if a package is installed or not

    dpkg -l | grep package-name
    

The last one could not give the desired result, because when the terminal width is narrow the columns are truncated. Safer alternatives are

dpkg-query -Wf '${Package}\n' | grep pkg
dpkg --get-selections | grep pkg

Solution 2:

To answer your last question about finding packages that are no longer necessary. You can find packages that are no longer necessary by

sudo deborphan

Also aptitude is per default set to automatically remove unused packages, so I'd suggest you use it instead of apt-get (it has other nice features too). Note that you may have to install deborphan and aptitude since they're not in the default install (they can be installed via apt-get).

If you wanna stick with apt-get you can removed unused packages with

sudo apt-get autoremove

However, I've found that deborphan manages to find more unused packages than both aptitude and apt-get.

Finally, note that both a aptitude and apt-get can remove old packages from the archives on your computer with the autoclean option:

sudo aptitude autoclean
sudo apt-get autoclean

Aptitude can also be set so that it does this automatically.