dpkg -l list all Packages available at your system. This will be piped to the awk-code which will search for nvidia in every line and print if found the name of the package. This code with the $() builds a variable for every found of "nvidia" and the "apt-get purge" uninstall all these founds incl. their configs.