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





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