![]() # = sudo apt remove linux-modules-5.11.0-44-generic linux-modules-5.11.0-46-generic # = dpkg-query -show 'linux-modules-*' | cut -f1 | grep -v "5.15.0-48-generic"įinally, we just use this list as arguments to the sudo apt remove command, which is probably so familiar to people at this point it doesn't need much explanation: $ sudo apt remove $(dpkg-query -show 'linux-modules-*' | cut -f1 | grep -v "$(uname -r)") $ dpkg-query -show 'linux-modules-*' | cut -f1 | grep -v "$(uname -r)" This is how we select all linux-modules packages which are not currently running. The "$(uname -r)" returns a line like 5.15.0-48-generic, which is then used as the pattern to grep. We pipe the output of that into the grep command, which lets us select lines that match a certain pattern - or, in this case, lines that don't match a certain pattern, using the -v|-invert-match option. In this case, it takes the output of our dpkg-query command and returns the first column: $ dpkg-query -show 'linux-modules-*' | cut -f1 The cut command simply takes standard input, an optional delimiter provided with -d (a tabulator character by default), and a field argument provided with -f. Linux-modules-5.11.0-46-generic 5.11.0-46.51~20.04.1Ī determined reader could probably figure out how to use the -showformat option to skip this step, but I preferred a more familiar approach - the cut command. ![]() You can use -list for a pretty, interactive display, but I chose to use -show to make scripting simpler. ![]() The second command to look at is dpkg-query, which lets us query installed packages in different ways. This prints the release number of your currently-running Linux kernel, in a format such as this: $ uname -r TL DR: sudo apt remove $(dpkg-query -show 'linux-modules-*' | cut -f1 | grep -v "$(uname -r)") Your distribution might come with packages that depend on a meta-package, such as linux-generic-hwe-20.04 for Ubuntu 20.04 LTS-based distributions, and I haven't tested this script when running an older Linux after installing a newer one. Note that I've only tested this when already running the latest Linux kernel installed on my distribution. Uninstall all linux-modules-* packages (and depending linux-image-* packages) which are not running. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |