Score:1

Can't seem to delete old Xubuntu kernels, I'm getting the error that the directory isn't empty or that I don't have permission to delete it

pa flag

I'm new to Linux so I might need some help in ELI5 language. I'm out of disk space. I see lots of old kernels that I don't need anymore, but I can't seem to delete them.

When I try this:

sudo apt clean && sudo apt autoclean && sudo apt autoremove -y

I get this:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 107 not upgraded.

Many kernels still remain afterwards. When I try to remove them manually, using this command:

sudo apt-get autoremove linux-image-4.4.0-31-generic

When I do this manually instead, I get this:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  linux-image-5.15.0-41-generic*
0 upgraded, 0 newly installed, 1 to remove and 107 not upgraded.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 260814 files and directories currently installed.)
Purging configuration files for linux-image-5.15.0-41-generic (5.15.0-41.44~20.04.1) ...
rmdir: failed to remove '/lib/modules/5.15.0-41-generic': Directory not empty

I don't think that it is true that the directory is empty though, because just this one specific directory is taking up 1.6gb. See screenshot of that here.

Can someone help me figure out how to remove these old kernels? It looks like they are taking up a lot of space, and I only have 2 GB left!

Score:0
gt flag
sudo -i
rm -r /lib/modules/5.15.0-41-generic

command to delete:

rm [option] FileOrFolderName

Use a recursive option, represented by -r, to remove the directory and its content. The following command shows how to delete Simple-Directory and its content:

rm -r Simple-Directory

related: how-to-remove-files-and-folders-using-linux-command-line

user535733 avatar
cn flag
Good place to mention that the system can be VERY sensitive to typographical errors, and this is one of those times. Check your spelling and spacing carefully...twice...before hitting `<enter>`.
slowsounds avatar
pa flag
This worked! Thank you!
Talaat Etman avatar
gt flag
@slowsounds good news, can you accept my answer please
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.