$ dpkg -l | head -n 4
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
Note all those | and / characters in the left edge... they are meant to point out the first two (three?) characters in the list of packages that follow these four lines (when you remove head -n 4 and actually list the packages).
If the two first characters are
ii - then the package listed on that line is actually installed
All other possible combinations are listed in those first four lines.
So
dpkg -l | grep -E '^ii' lists all actually installed packages.
dpkg -l | grep -E '^.H' should list software in Half-inst state.
I'm not sure what "deinstall" would correspond to.
Then
sudo apt install package-name - to install a package
sudo apt remove package-name - to remove (uninstall) a package
sudo apt purge package-name - to remove a package and it's config/settings files.