使用awk,sed删除所有未使用的内核

・2 分钟阅读

删除所有未使用的内核

aptitude remove $(dpkg -l|awk '/^ii linux-image-2/{print $2}'|sed 's/linux-image-//'|awk -v v=`uname -r` 'v>$0'|sed 's/-generic//'|awk '{printf("linux-headers-%snlinux-headers-%s-genericnlinux-image-%s-genericn",$0,$0,$0)}')
注意双空格:" ... ^iLinux-image-2 ... "类似5813,但是,修复了两个错误: [1]单独留下了元包'linux-headers-generic'和'linux-image-generic',以便自动升级在未来正常工作,比当前运行的内核新的[2]内核是单独的(如果在安装新内核后,没有重新启动,则可能发生这种情况),我很不高兴这部电影总共有228个角色,我想看看更简单的版本,
示例输出
The following packages will be REMOVED: 
 linux-headers-2.6.32-24 linux-headers-2.6.32-24-generic linux-headers-2.6.32-25 linux-headers-2.6.32-25-generic linux-headers-2.6.35-22 
 linux-headers-2.6.35-22-generic linux-image-2.6.32-24-generic linux-image-2.6.32-25-generic linux-image-2.6.35-22-generic 
0 packages upgraded, 0 newly installed, 9 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 566MB will be freed.
Hujiuxiang profile image