Linux归档压缩、脚本编程之循环控制

一、Linux归档压缩

在一些备份服务器上为了节省硬盘空间以存储更多的内容,压缩是一个不错的选择,虽然压缩是拿cpu的时间去换硬盘空间有时并不合算。Linux的压缩工具一般只能压缩单个文本文件,如果要压缩一个目录,就必须先将目录打包归档。Linux有很多不同的压缩的工具,一般压缩比越大可能占用cpu的时间更长,下面来瞧一瞧Linux有哪些常用的工具吧。

1、compress、uncompress和zcat:压缩,展开数据,压缩文件后缀是.Z,此压缩工具已过时。

compress压缩默认会删除原文件

语法:compress [-dfvcVr] [-b maxbits] [files......]

选项:

-d:解压缩相当于uncompress

-c:将压缩后的文件输出到标准输出,不会删除原文件,可通过重定向来实现压缩并保留原文件

-b:设定共同字串数的上限,以位元计算,可以设定的值为 9 至 16 bits 。由于值越大,能使用的共同字串就 越多,压缩比例就越大,所以一般使用预设值 16 bits (bits)

[root@localhost blog1]# ll -h
total 203M
-rw-r--r--. 1 root root 102M Aug 16 21:02 locale-archive
-rw-r--r--. 1 root root 102M Aug 16 21:04 locale-archive.bak
[root@localhost blog1]# compress locale-archive
[root@localhost blog1]# ll -h
total 148M
-rw-r--r--. 1 root root 102M Aug 16 21:04 locale-archive.bak
-rw-r--r--. 1 root root  47M Aug 16 21:02 locale-archive.Z
[root@localhost blog1]# compress -b 9 -c locale-archive.bak > locale-archivebak.Z
[root@localhost blog1]# ll -h
total 213M
-rw-r--r--. 1 root root 102M Aug 16 21:04 locale-archive.bak
-rw-r--r--. 1 root root  66M Aug 16 21:08 locale-archivebak.Z
-rw-r--r--. 1 root root  47M Aug 16 21:02 locale-archive.Z

-f:如果压缩后的文件名在指定的目录已存在,默认将提示用户是否覆盖,-f选项将无提示复盖已存在文件。注:如果要压缩的文件有多个硬连接,compresse默认无法压缩,-f选项可强制压缩,压缩后硬连接数减一。

-v:打印压缩信息,将会打印压缩掉的大小占原文件大小的百分比

-V:打印版本信息和编译选项

-r:递归压缩,如果目标是一个目录,-r选项将进入到目录里将里面的文件压缩,如果有子目录,则进入子目录压缩

zcat在解压之前查看压缩包里的文件,zcat通过重定向可实现解压缩

[root@linux blog1]# zcat local.Z > local
[root@linux blog1]# ll -h
total 249M
-rw-r--r--. 1 root root 102M Aug 17 18:04 local
-rw-r--r--. 1 root root 102M Aug 17 18:03 locale-archive
-rw-r--r--. 1 root root  47M Aug 17 18:03 local.Z

2、gzip/gunzip:比较流行的一个压缩工具,压缩默认会删除原文件,后缀为:.gz

用法:gzip [option]... [file]...

选项:

-c:保留原文件,将压缩后的文本输出到标准输出,可通过重定向生成压缩文件

-d:解压缩

-f:强制覆盖同名文件,强制压缩硬连接文件

-l:列出压缩文件的内容

[root@linux blog1]# gzip -l local.gz 
         compressed        uncompressed  ratio uncompressed_name
           23874038           106065056  77.5% local

-L:显示软件许可

-n:压缩时不保存原始名和时间戳,解压时也不保留,解压时为默认选项

-N:压缩时保留原始名和时间戳,解压时也保留,压缩时为默认选项

[root@linux opt]# ll
total 103580
-rw-r--r--. 1 root root 106065067 Aug 17 10:07 local
[root@linux opt]# gzip -cn local > loc.gz
[root@linux opt]# gzip -cN local > loca.gz
[root@linux opt]# ll
total 150212
-rw-r--r--. 1 root root  23874048 Aug 17 10:10 loca.gz
-rw-r--r--. 1 root root 106065067 Aug 17 10:07 local
-rw-r--r--. 1 root root  23874042 Aug 17 10:09 loc.gz
[root@linux opt]# gunzip -n loc.gz
[root@linux opt]# gunzip -N loca.gz
gzip: local already exists; do you wish to overwrite (y or n)? y
[root@linux opt]# ll
total 207160
-rw-r--r--. 1 root root 106065067 Aug 17 10:09 loc  #########
-rw-r--r--. 1 root root 106065067 Aug 17 10:07 local#########时间戳都保留下来了
[root@linux opt]# date
Wed Aug 17 10:24:38 CST 2016
[root@linux opt]# gzip -c local > loc.gz
[root@linux opt]# gzip -c local > local.gz
[root@linux opt]# ll
total 253792
-rw-r--r--. 1 root root 106065067 Aug 17 10:09 loc
-rw-r--r--. 1 root root 106065067 Aug 17 10:07 local
-rw-r--r--. 1 root root  23874048 Aug 17 10:25 local.gz
-rw-r--r--. 1 root root  23874048 Aug 17 10:25 loc.gz
[root@linux opt]# mv local.gz /mnt/
[root@linux opt]# mv loc.gz /mnt/
[root@linux opt]# cd /mnt/
[root@linux mnt]# ll
total 46632
-rw-r--r--. 1 root root 23874048 Aug 17 10:25 local.gz
-rw-r--r--. 1 root root 23874048 Aug 17 10:25 loc.gz
[root@linux mnt]# gunzip -N local.gz 
[root@linux mnt]# gunzip -n loc.gz
[root@linux mnt]# ll
total 207160
-rw-r--r--. 1 root root 106065067 Aug 17 10:25 loc   ########保留了上一次压缩文件的时间戳
-rw-r--r--. 1 root root 106065067 Aug 17 10:07 local########保留最原始的时间戳

-q:忽略所有的警告信息

-r:递归压缩

-S:更改压缩字尾字符串

-t:测试压缩

-v:冗长的信息

-1到-9:指定压缩比,1的压缩比最小,压缩耗费时间最少;9压缩比最大,最耗费时间;默认为6

3、bzip2/bunzip2/bzcat:块类文件的压缩工具,对于大文件有比gzip更好的压缩效果,但对于小文件二者压缩效果差别不大bzip2将耗费更多的时间。压缩后缀为.bz2

常用选项:

-d:强制解压缩

-z:强制解压缩

-k:压缩不删除原文件,默认会删除原文件

-f:覆盖已存在的同名文件

-t:压缩测试

-c:将压缩文件送到标准输出

-q:屏蔽非紧急的错误信息

-v/-vv:打印冗长的信息

-s:使用最少的内存(最少是2500K)

-1..-9:设置块大小100K..900K,压缩时的区块大小

http://www.jb51.net/LINUXjishu/424315.html

4、xz/unxz/xzcat,和xz类似的压缩工具lzma/unlzma/lzcat,压缩后缀为.xz

选项:

-z:强制压缩

-d:强制解压缩

-t:测试压缩

-l:列出.xz压缩文件的信息

-k:保留原文件,默认删除

-f:强制覆盖

-c:压缩文件送到标准输出

-e:通过使用更多的CPU时间来进一步提高压缩比

-T:多线程压缩,使用给定的数字设置能使用的最多线程,默认为1,设为0时使用核心数

[root@linux blog1]# xz -e -T8 -k local
[root@linux blog1]# ll -h
total 296M
-rw-r--r--. 1 root root 102M Aug 17  2016 local
-rw-r--r--. 1 root root  21M Aug 17  2016 local.bz2
-rw-r--r--. 1 root root 102M Aug 17  2016 locale-archive
-rw-r--r--. 1 root root  23M Aug 17 11:06 local.gz
-rw-r--r--. 1 root root 3.7M Aug 17  2016 local.xz ####丧心病狂的压缩比和等待时间
-rw-r--r--. 1 root root  47M Aug 17  2016 local.Z

-H:显示详细的帮助,包括高级选项

当没有指定文件时或使用-,从标准输入读取


以上工具都不支持打包归档操作,当要压缩整个目录时,需要先将目录打包,常用的工具有tar、cpio和zip。

5、先来看看比较简单的zip/unzip,zip支持多个平台(Linux、Windows等),但是压缩的效率不好

usage:zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]

基本命令:zip options archive_name file1 file2 ......

-r:压缩目录

  

6、tar:堪称Linux的打包压缩神器,日常工作用的最多,默认保留原文件。tar命令的用法有许多,其info帮助文档非常冗长详细,这里将介绍一些常用的用法。

usage:tar [option]... [file]...

-f:通用选项,指定file.tar的路径

  • 创建归档

-c -f:创建归档,tar创建归档时会自动删掉目前的根目录号,以防解压时覆盖了原来的目录

注意:cf顺序不能颠倒。

  • 展开归档

-x -f:展开归档,默认展开到当前目录

-C;指定展开的路径

  • 查看归档中的文件列表

-t -f:查看归档中的文件

  • 归档后压缩

-z:gzip,以.gz格式压缩归档

    -zcf 归档压缩后的文件名 file或dir...

    -zxf 展开压缩归档,展开时tar可自己识别压缩格式,即任何压缩都可用xf解压。

-j:bzip2

    -jcf

    -jxf

-J:xz

    -Jcf

    -Jxf

7、cpio :通过重定向的方式将文件进行打包备份,还原恢复的工具,它可以解压以“.cpio”或者“.tar”结尾的文件。

usage:

cpio [选项] > 文件名或者设备名

cpio [选项] < 文件名或者设备名

选项:

-o:将文件拷贝打包成文件或者将文件输出到设备上

-i:解包,将打包文件解压或设备上的备份还原到系统

-t:预览,查看文件内容或者输出到设备上的文件内容

-v;显示打包过程中的文件名称

-d:解压生成目录,cpio时,自动建立目录

-c:一种较新的存储方式

[root@linux opt]# find /etc/ -user root |cpio -ovc > hh.cpio
[root@linux opt]# ll -h
total 244M
-rw-r--r--. 1 root root  19M Aug 17 14:47 hh.cpio
[root@linux ~]# cpio -vt < /opt/hh.cpio
drwxr-x---   2 root     root            0 Nov 21  2015 /etc/sudoers.d
-rw-r--r--   1 root     root          112 Mar  6  2015 /etc/e2fsck.conf
-rw-r--r--   1 root     root          936 Mar  6  2015 /etc/mke2fs.conf
-rw-r--r--   1 root     root           37 Aug 17  2016 /etc/vconsole.conf
-rw-r--r--   1 root     root           19 Aug 17  2016 /etc/locale.conf
-rw-r--r--   1 root     root            6 Aug 17  2016 /etc/hostname
-rw-r--r--   1 root     root          163 Aug 17  2016 /etc/.updated
-rw-r--r--   1 root     root        12288 Aug 17  2016 /etc/aliases.db

注意:cpio打包压缩时不会删掉根目录,还原时一定要注意

[root@linux ~]# cpio -iv < /opt/hh.cpio
[root@linux ~]# cpio -idv < /opt/hh.cpio
cpio: /etc/mke2fs.conf not created: newer or same age version exists
/etc/mke2fs.conf
cpio: /etc/vconsole.conf not created: newer or same age version exists
/etc/vconsole.conf
cpio: /etc/locale.conf not created: newer or same age version exists
/etc/locale.conf
cpio: /etc/hostname not created: newer or same age version exists
/etc/hostname
cpio: /etc/.updated not created: newer or same age version exists
/etc/.updated
cpio: /etc/aliases.db not created: newer or same age version exists


二、脚本编程之循环控制

1、for循环

for 变量名 in 列表;do

    循环体

done

依次将列表中的元素赋值给“变量名”; 每次赋值后即执行一次循环体; 直到列表中的元素耗尽,循环结束

循环列表的生成方法:

  1. 直接给出列表,注意以空格分割

  2. 整数列表

    {start .. end}、$(seq [start [step]] end)

  3. 返回列表的命令

    $(command)

  4. 使用glob,如:*.sh

  5. 变量引用:$*、$@

for的循环列表可以用(()),括号里可以实现c语言风格的循环



2、while循环

while condition;do

    循环体

done

CONDITION:循环控制条件;进入循环之前,先做一次判断;每一次循环之后会再次做判断;条件为“true”,则执行一次循环;直到条件测试状态为“false”终止循环,因此:CONDTION一般应该有循环控制变量;而此变量的值会在循环体不断地被修正

特殊用法:

while read line;do

    循环体

done < /PATHOFFILE

依次读取/PATH/FROM/SOMEFILE文件中的每一行,且将行赋值给变量line


3、until循环

until condition ;do

    循环体

done

同while循环相反,进入条件:CONDITION 为false,退出条件:CONDITION 为true。


4、循环控制语句continue、break和exit

continue:

continue [N]:提前结束第N层的本轮循环,而直接进入下一次循环,最内层为第一层

[root@linux blog1]# bash continue.sh 
最外层: 1
第一层: 1
第一层: 2
最外层: 2
第一层: 1
第一层: 2
最外层: 3
第一层: 1
第一层: 2
最外层: 4
第一层: 1
第一层: 2
最外层: 5
第一层: 1
第一层: 2
[root@linux blog1]# cat continue.sh
#!/bin/bash
for i in {1..5};do
    echo "最外层: $i"
        for j in {1..5};do
            if [ $j -eq 3 ];then
                continue 2
            fi
            echo "第一层: $j"
        done
done

break:

break[N]:提前结束第N层循环,最内层为第一层

[root@linux blog1]# bash break.sh
The last layer: 1
The second layer: 1
The first layer: 1
The first layer: 2
The last layer: 2
The second layer: 1
The first layer: 1
The first layer: 2
The last layer: 3
The second layer: 1
The first layer: 1
The first layer: 2
The last layer: 4
The second layer: 1
The first layer: 1
The first layer: 2
The last layer: 5
The second layer: 1
The first layer: 1
The first layer: 2
[root@linux blog1]# cat break.sh
#!/bin/bash
for i in {1..5};do
    echo "The last layer: $i"
    for j in {1..5};do
        echo "The second layer: $j"
        for k in {1..5};do
            if [ $k -eq 3 ];then
                break 2
            fi
            echo "The first layer: $k"
        done
    done
done

exit:

exit:退出整个进程,只退出当前进程

[root@linux blog1]# bash exit.sh
The last layer: 1
The second layer: 1
The first layer: 1
The first layer: 2
The second layer: 2
The first layer: 1
The first layer: 2
The second layer: 3
The first layer: 1
The first layer: 2
The second layer: 4
The first layer: 1
The first layer: 2
The second layer: 5
The first layer: 1
The first layer: 2
The last layer: 2
The second layer: 1
The first layer: 1
The first layer: 2
The second layer: 2
The first layer: 1
The first layer: 2
The second layer: 3
The first layer: 1
The first layer: 2
The second layer: 4
The first layer: 1
The first layer: 2
The second layer: 5
The first layer: 1
The first layer: 2
The last layer: 3
The second layer: 1
The first layer: 1
The first layer: 2
The second layer: 2
The first layer: 1
The first layer: 2
The second layer: 3
The first layer: 1
The first layer: 2
The second layer: 4
The first layer: 1
The first layer: 2
The second layer: 5
The first layer: 1
The first layer: 2
The last layer: 4
The second layer: 1
The first layer: 1
The first layer: 2
The second layer: 2
The first layer: 1
The first layer: 2
The second layer: 3
The first layer: 1
The first layer: 2
The second layer: 4
The first layer: 1
The first layer: 2
The second layer: 5
The first layer: 1
The first layer: 2
The last layer: 5
The second layer: 1
The first layer: 1
The first layer: 2
The second layer: 2
The first layer: 1
The first layer: 2
The second layer: 3
The first layer: 1
The first layer: 2
The second layer: 4
The first layer: 1
The first layer: 2
The second layer: 5
The first layer: 1
The first layer: 2
[root@linux blog1]# cat exit.sh
#!/bin/bash
for i in {1..5};do
    echo "The last layer: $i"
    (for j in {1..5};do
        echo "The second layer: $j"
        (for k in {1..5};do
            if [ $k -eq 3 ];then
                exit 2
            fi
            echo "The first layer: $k"
        done)
    done)
done

和break 1的效果一样


5、select循环,主要用于创建菜单,按数字顺序排列的菜单项将显示在标准错误上,并显示PS3 提示符,等待用户输入

用户输入菜单列表中的某个数字,执行相应的命令

用户输入被保存在内置变量REPLY 中

select var in list;do

    循环体命令

done

select 是个无限循环,因此要记住用break 命令退出循环,或用exit 命令终止脚本。也可以按ctrl+c 退出循环。

select 经常和case 联合使用

与for 循环类似,可以省略in list ,此时使用位置参量




练习:

用until实现下列的问题

1、每隔3秒钟到系统上获取已经登录的用户的信息;如果发现用户hacker登录,则将登录时间和主机记录于日志/var/log/login.log中,并提示该用户退出系统。

[root@linux blog1]# bash userlogin.sh
hacker doesnot login
hacker doesnot login
......
###使用hacker登陆后
Message from root@linux on <no tty> at 17:16 ...
You are forbidden to login,please logout at once!
EOF
Message from root@linux on <no tty> at 17:17 ...
You are forbidden to login,please logout at once!
EOF
hacker doesnot login
Message to hacker is sent
hacker doesnot login
Message to hacker is sent
[root@linux blog1]# cat userlogin.sh
#!/bin/bsh
until false;do
    if   w -h|grep hacker &>/dev/null 
    then
        w -h|grep hacker|tr -s ' ' |cut -d ' ' -f3,4 >> /var/log/login.log
        echo "You are forbidden to login,please logout at once!"|write hacker &> /dev/null
        echo "Message to hacker is sent"
    fi
    echo "hacker doesnot login"
    sleep 3
done

2、随机生成10以内的数字,实现猜字游戏,提示比较大或小,相等则退出

[root@linux blog1]# bash guessnum.sh
please enter your num[0-10]: 9
you are wrong,guess again!
please enter your num[0-10]: 2
you are wrong,guess again!
please enter your num[0-10]: 3
you are wrong,guess again!
please enter your num[0-10]: 4
you are wrong,guess again!
please enter your num[0-10]: 5
you are wrong,guess again!
please enter your num[0-10]: 6
You are very luchy!
[root@linux blog1]# cat guessnum.sh
#!/bin/bash
until false;do
    rannum=$[$RANDOM%11]
    read -p "please enter your num[0-10]: " num
    if [ $rannum -eq $num ];then
        echo "You are very luchy!"
        break
    else
        echo "you are wrong,guess again!"
    fi
done

3、编写脚本,求100以内所有正整数之和

[root@linux blog1]# bash sum100.sh
Please enter the bigger num: 100
Please enter the smaller num: 1
The total num is 5050
[root@linux blog1]# bash sum100.sh
Please enter the bigger num: 1000
Please enter the smaller num: 500
The total num is 375750
[root@linux blog1]# cat sum100.sh
#!/bin/bash
read -p "Please enter the bigger num: " bigger
read -p "Please enter the smaller num: " smaller
sum=0
until [ $bigger -lt $smaller ];do
    let sum+=$smaller
    let smaller++
done
echo "The total num is $sum"

4、编写脚本,通过ping命令探测172.16.250.1-254范围内的所有主机的在线状态,统计在线主机和离线主机各多少。

[root@linux blog1]# bash ping.sh
Please enter the ip(like 1.1.1.1): 10.1.253.0
10.1.253.0 is down
10.1.253.1 is down
10.1.253.2 is down
10.1.253.3 is down
10.1.253.4 is down
10.1.253.5 is down
10.1.253.6 is down
10.1.253.7 is down
10.1.253.8 is up
10.1.253.9 is down
.........
10.1.253.253 is down
10.1.253.254 is down
10.1.253.255 is down
The total ip which is up:14
The total ip which is down:242
[root@linux blog1]#
[root@linux blog1]# cat ping.sh
#!/bin/bash
read -p "Please enter the ip(like 1.1.1.1): " ipall
ip_addr=`echo $ipall |cut -d. -f1-3`
last=0
pingS=0
pingF=0
until [ $last -gt 255 ];do
    if ping -c1 -w1 ${ip_addr}.$last &>/dev/null
    then
        echo "${ip_addr}.$last is up"
        let pingS++
    else
        echo "${ip_addr}.$last is down"
        let pingF++
    fi
    let last++
    sleep 0.1
done
echo "The total ip which is up:$pingS"
echo "The total ip which is down:$pingF"

5、编写脚本,打印九九乘法表

[root@linux blog1]# bash multitable.sh
1x1=1    
2x1=2    2x2=4    
3x1=3    3x2=6    3x3=9    
4x1=4    4x2=8    4x3=12    4x4=16    
5x1=5    5x2=10    5x3=15    5x4=20    5x5=25    
6x1=6    6x2=12    6x3=18    6x4=24    6x5=30    6x6=36    
7x1=7    7x2=14    7x3=21    7x4=28    7x5=35    7x6=42    7x7=49    
8x1=8    8x2=16    8x3=24    8x4=32    8x5=40    8x6=48    8x7=56    8x8=64    
9x1=9    9x2=18    9x3=27    9x4=36    9x5=45    9x6=54    9x7=63    9x8=72    9x9=81
[root@linux blog1]# cat multitable.sh
#!/bin/bash
line=1
until [ $line -gt 9 ];do
    row=1
    until [ $row -gt $line ];do
        echo -ne "${line}x${row}=$[line*row]\t"
        let row++
    done
    echo
    let line++
done

6、编写脚本,利用变量RANDOM生成10个随机数字,输出这个10数字,并显示其中的最大者和最小者

[root@linux blog1]# cat random.sh
#!/bin/bash
max=$RANDOM
min=$RANDOM
echo "The random is: $max"
echo "The random is: $min"
if [ $max -lt $min ];then
    mid=$max
    max=$min
    min=$mid
fi
i=1
until [ $i -gt 8 ];do
    mid=$RANDOM
    echo "The random is: $mid"
    if [ $mid -gt $max ];then
        c=$mid
        mid=$max
        max=$c
    fi
    if [ $mid -lt $min ];then
        c=$min
        min=$mid
        mid=$c
    fi
    let i++
done
echo -e "\033[31m-------------------------\033[0m"
echo "the max num is: $max"
echo "the min num is: $min"
[root@linux blog1]# bash random.sh
The random is: 25641
The random is: 18437
The random is: 20789
The random is: 1052
The random is: 1937
The random is: 28962
The random is: 28954
The random is: 2717
The random is: 29918
The random is: 10578
-------------------------
the max num is: 29918
the min num is: 1052
[root@linux blog1]# bash random2.sh
the random is 4013
the random is 13009
the random is 24430
the random is 18854
the random is 20264
the random is 20586
the random is 31832
the random is 6138
the random is 11674
the random is 31771
max: 31832
min: 4013
[root@linux blog1]# cat random2.sh
#!/bin/bash
mid=$RANDOM
max=$mid
min=$mid
echo "the random is $mid"
i=1
until [ $i -gt 9 ];do
    mid=$RANDOM
    echo "the random is $mid"
    if [ $mid -gt $max ];then
        max=$mid
    fi
    if [ $mid -lt $min ];then
        min=$mid
    fi
    let i++
done
echo "max: $max"
echo "min: $min"

7、编写脚本,实现打印国际象棋棋盘

[root@linux blog1]# cat chess.sh
#!/bin/bash
read -p "Please enter the num:" num
line=1
until [ $line -gt $num ];do
    row=1
    until [ $row -gt $num ];do
        let sum=line+row
        let sum=$[$sum%2]
        if [ $sum -eq 0 ];then
            echo -en "\033[47m  \033[0m"
        else
            echo -en "\033[43m  \033[0m"
        fi
        let row++
    done
    echo
    let line++
done

wKiom1e0XneBxMadAAAqdpHGcBM410.png

8、打印等腰三角形

[root@linux blog1]# cat trigon.sh
#!/bin/bash
read -p "please enter a odd: " line
if [ $(($line%2)) -eq 0 ];then
    echo "Must a odd"
fi
total=$[2*$line-1]
i=1
until [ $i -gt $total ];do
    if [ $i -le $line ];then
        j=1
        until [ $j -gt $(($line-$i)) ];do
            echo -en " "
            let j++
        done
        k=1
        until [ $k -gt $((2*$i-1)) ];do
            echo -en "*"
            let k++
        done
    else
        l=1
        until [ $l -gt $(($i-$line)) ];do
            echo -en " "
            let l++
        done
        m=1
        until [ $m -gt $(($total+2*$line-2*$i)) ];do
            echo -en "*"
            let m++
        done
    fi
    echo
    let i++
done

wKiom1e0b3uy_3bRAAA44CC47dM056.png

9、安装centos6.7,用centos6.8kernel升级(由于我只有centos7.2和centos6.8的镜像,实验将给centos7.2安装centos6.8的内核)

[root@linux ~]# rpm -q kernel
kernel-3.10.0-327.el7.x86_64
[root@linux ~]# rpm -ivh kernel-2.6.32-642.el6.x86_64.rpm --oldpackage
warning: kernel-2.6.32-642.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:kernel-2.6.32-642.el6            ################################# [100%]
depmod: WARNING: could not open /lib/modules/2.6.32-642.el6.x86_64/modules.builtin: No such file or directory
depmod: WARNING: could not open /var/tmp/initramfs.UZubZb/lib/modules/2.6.32-642.el6.x86_64/modules.builtin: No such file or directory
[root@linux ~]# rpm -q kernel
kernel-3.10.0-327.el7.x86_64
kernel-2.6.32-642.el6.x86_64
[root@linux ~]# ls /boot/
config-2.6.32-642.el6.x86_64
config-3.10.0-327.el7.x86_64
grub
grub2
initramfs-0-rescue-6f7a172ba61f472db6b9ac28b9c75e61.img
initramfs-2.6.32-642.el6.x86_64.img
initramfs-3.10.0-327.el7.x86_64.img
initramfs-3.10.0-327.el7.x86_64kdump.img
initrd-plymouth.img
symvers-2.6.32-642.el6.x86_64.gz
symvers-3.10.0-327.el7.x86_64.gz
System.map-2.6.32-642.el6.x86_64
System.map-3.10.0-327.el7.x86_64
vmlinuz-0-rescue-6f7a172ba61f472db6b9ac28b9c75e61
vmlinuz-2.6.32-642.el6.x86_64
vmlinuz-3.10.0-327.el7.x86_64





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章