[shell:bash] ubuntu_remove_old_kernel_test
一、基本信息
1、 os: Linux ubuntu 6.5.0-35-generic #35-Ubuntu SMP PREEMPT_DYNAMIC Fri Apr 26 11:23:57 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
2、 bash: GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu)
二、脚本内容:ubuntu_remove_old_kernel_test
1 [wit@ubuntu:bash]$ cat ubuntu_remove_old_kernel_test
2 #/usr/bin/bash
3
4
5
6
7 echo -e "\n\n"
8 echo " [bash]# list using kernel "
9 echo -e "\n"
10 sudo uname -a
11
12
13
14
15 echo -e "\n\n"
16 for num in 25 27 28
17 do
18
19 linux_header="linux-headers-6.5.0-${num}"
20 linux_header_generic="linux-headers-6.5.0-${num}-generic"
21 linux_image="linux-image-6.5.0-${num}-generic"
22 linux_mod="linux-modules-6.5.0-${num}-generic"
23 linux_mod_ex="linux-modules-extra-6.5.0-${num}-generic"
24
25
26 echo -e "\n\n\n"
27 echo " [bash]# remove: ${linux_header}"
28 echo
29 sudo apt purge -y ${linux_header}
30
31 echo -e "\n\n\n"
32 echo " [bash]# remove: ${linux_header_generic}"
33 echo
34 sudo apt purge -y ${linux_header_generic}
35
36 echo -e "\n\n\n"
37 echo " [bash]# remove: ${linux_image}"
38 echo
39 sudo apt purge -y ${linux_image}
40
41 echo -e "\n\n\n"
42 echo " [bash]# remove: ${linux_mod}"
43 echo
44 sudo apt purge -y ${linux_mod}
45
46 echo -e "\n\n\n"
47 echo " [bash]# remove: ${linux_mod_ex}"
48 echo
49 sudo apt purge -y ${linux_mod_ex}
50
51 done
52
53
54
55
56 echo -e "\n\n\n"
57 echo " [bash]# list remain kernel files"
58 echo
59 dpkg --get-selections | grep linux
60
61
62
63
64 echo -e "\n\n\n"
65 echo " [bash]# update--grub2"
66 echo
67 sudo update-grub2
68
69
70
71
72 echo -e "\n\n\n"
73 echo " [bash]# list using kernel "
74 echo
75 sudo uname -a
76
77
78
79
80 echo -e "\n\n\n"
81
82
83
84
85 [wit@ubuntu:bash]$
三、参考资料:
1、 Shell教程|菜鸟教程 -- https://www.runoob.com/linux/linux-shell.html
本文由 lnlidawei 原创、整理、转载,本文来自于【博客园】; 整理和转载的文章的版权归属于【原创作者】; 转载或引用时请【保留文章的来源信息】:https://www.cnblogs.com/lnlidawei/p/18192308