本文是阅读 《鸟哥的 Linux 私房菜:基础学习篇》
一书的笔记,记录了个人认为的一些重点内容,供本人后续查阅参考。对于偏向于系统运维方面的内容,则未记录。
《鸟哥的 Linux 私房菜:基础学习篇》无疑是入门 Linux
命令行的一本好书,但是在个人阅读过程中,发现本书部分内容更偏向于系统运维人员,而不是大多数的普通程序员。当然,技多不压身,不过,对于仅想了解与日常编程开发紧密相关的命令行内容的读者,不妨选择性地跳跃阅读本书,或者找一些更符合您需求的资料。
$ man date # man 为 manual(操作说明)的缩写 # 按下 空格键 翻页;q 退出 # 向下查找词语: 输入 “/word” ,然后按 Enter 键,即可查找 “word” # 向上查找词语: 输入 “?word” ,然后按 Enter 键,即可查找 “word”
# 查看 man 的帮助 $ man man
# 查看系统中和 man 命令有关的说明文件 $ man -f man $ whatis [命令或文件] # 等价于上面 man -f ... man (7) - 格式化手册页的宏 man (1) - 格式化并显示在线帮助手册页 man (1p) - display system documentation $ man 1 man # 根据上面输出查看指定说明文件
# 找到系统中说明文件,只有有 man 关键字就将该说明列出来 $ man -k man $ apropos [命令或文件] # 相当于 man -k ...
#!/bin/bash # Program: # This program shows "Hello World!"in your screen. # History: # 2015/07/16 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH echo -e "Hello World! \a \n" exit 0
良好的script 撰写习惯,在每个script 的档头处记录好:
script 的功能;
script 的版本资讯;
script 的作者与联络方式;
script 的版权宣告方式;
script 的History (历史纪录);
script 内较特殊的指令,使用『绝对路径』的方式来下达;
script 运作时需要的环境变量预先声明与设置。
12.2 简单的 shell 脚本练习
处理用户输入:
1 2 3 4 5 6 7 8 9 10 11
#!/bin/bash # Program: # User inputs his first name and last name. Program shows his full name. # History: # 2015/07/16 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH
read -p "Please input your first name: " firstname # 提示使用者输入 read -p "Please input your last name: " lastname # 提示使用者输入 echo -e "\nYour full name is: ${firstname} ${lastname}" # 结果由屏幕输出
#!/bin/bash # Program: # Program creates three files, which named by user's input and date command. # History: # 2015/07/16 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH
# 1. 让使用者输入档案名称,并取得fileuser 这个变数; echo -e "I will use 'touch' command to create 3 files." # 纯粹显示资讯 read -p "Please input your filename: " fileuser # 提示使用者输入
#!/bin/bash # Program: # User inputs 2 integer numbers; program will cross these two numbers. # History: # 2015/07/16 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH echo -e "You SHOULD input 2 numbers, I will multiplying them! \n" read -p "first number: " firstnu read -p "second number: " secnu total=$((${firstnu}*${secnu})) echo -e "\nThe result of ${firstnu} x ${secnu} is ==> ${total}"
计算含小数点数:
1
$ echo"123.123*55.9" | bc
计算 Pi
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/bin/bash # Program: # User input a scale number to calculate pi number. # History: # 2015/07/16 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH echo -e "This program will calculate pi value. \n" echo -e "You should input a float number to calculate pi value.\n" read -p "The scale number (10~10000) ? " checking num=${checking:-"10"} # 开始判断有否有输入数值 echo -e "Starting calculate pi value. Be patient." time echo "scale=${num}; 4*a(1)" | bc -lq
#!/bin/bash # Program: # User input a filename, program will check the flowing: # 1.) exist? 2.) file/directory? 3.) file permissions # History: # 2015/07/16 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH
# 1. 让使用者输入档名,并且判断使用者是否真的有输入字串? echo -e "Please input a filename, I will check the filename's type and permission. \n\n" read -p "Input a filename : " filename test -z ${filename} && echo "You MUST input a filename." && exit 0 # 2. 判断档案是否存在?若不存在则显示讯息并结束脚本 test ! -e ${filename} && echo "The filename '${filename}' DO NOT exist" && exit 0 # 3. 开始判断档案类型与属性 test -f ${filename} && filetype="regulare file" test -d ${filename} && filetype="directory" test -r ${filename} && perm="readable" test -w ${filename} && perm="${perm} writable" test -x ${filename} && perm="${perm} executable" # 4. 开始输出资讯! echo "The filename: ${filename} is a ${filetype}" echo "And the permissions for you are : ${perm}"
使用中括号 [] :
1 2 3 4 5 6 7 8 9 10 11 12
#!/bin/bash # Program: # This program shows the user's choice # History: # 2015/07/16 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH
read -p "Please input (Y/N): " yn [ "${yn}" == "Y" -o "${yn}" == "y" ] && echo "OK, continue" && exit 0 [ "${yn}" == "N" -o "${yn}" == "n" ] && echo "Oh, interrupt!" && exit 0 echo "I don't know what your choice is" && exit 0
shell 脚本的默认变量($0$1 ...):
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/bin/bash # Program: # Program shows the script name, parameters... # History: # 2015/07/16 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH
echo "The script name is ==> ${0}" echo "Total parameter number is ==> $#" [ "$#" -lt 2 ] && echo "The number of parameter is less than 2. Stop here." && exit 0 echo "Your whole parameter is ==> '$@'" echo "The 1st parameter ==> ${1}" echo "The 2nd parameter ==> ${2}"
12.4 条件判断式
12.4.1 if...then
单层、简单条件判断式:
1 2 3
if [条件判断式]; then 当条件判断式成立时,可以进行的指令工作内容; fi
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!/bin/bash # Program: # This program shows the user's choice # History: # 2015/07/16 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH
read -p "Please input (Y/N): " yn
if [ "${yn}" == "Y" ] || [ "${yn}" == "y" ]; then echo "OK, continue" exit 0 fi if [ "${yn}" == "N" ] || [ "${yn}" == "n" ]; then echo "Oh, interrupt!" exit 0 fi echo "I don't know what your choice is" && exit 0
多重、复杂条件判断式:
1 2 3 4 5 6
# 一个条件判断,分成功进行与失败进行(else) if [条件判断式]; then 当条件判断式成立时,可以进行的指令工作内容; else 当条件判断式不成立时,可以进行的指令工作内容; fi
1 2 3 4 5 6 7 8
# 多个条件判断(if ... elif ... elif ... else) 分多种不同情况执行 if [条件判断式一]; then 当条件判断式一成立时,可以进行的指令工作内容; elif [条件判断式二]; then 当条件判断式二成立时,可以进行的指令工作内容; else 当条件判断式一与二均不成立时,可以进行的指令工作内容; fi
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/bin/bash # Program: # This program shows the user's choice # History: # 2015/07/16 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH
read -p "Please input (Y/N): " yn
if [ "${yn}" == "Y" ] || [ "${yn}" == "y" ]; then echo "OK, continue" elif [ "${yn}" == "N" ] || [ "${yn}" == "n" ]; then echo "Oh, interrupt!" else echo "I don't know what your choice is" fi
从命令行获取用户输入:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/bin/bash # Program: # Check $1 is equal to "hello" # History: # 2015/07/16 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH
if [ "${1}" == "hello" ]; then echo "Hello, how are you ?" elif [ "${1}" == "" ]; then echo "You MUST input parameters, ex> {${0} someword}" else echo "The only parameter is 'hello', ex> {${0} hello}" fi
#!/bin/bash # Program: # Using netstat and grep to detect WWW,SSH,FTP and Mail services. # History: # 2015/07/16 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH
# 1. 先作一些告知的动作而已~ echo "Now, I will detect your Linux server's services!" echo -e "The www, ftp, ssh, and mail(smtp) will be detected! \n"
# 2. 开始进行一些测试的工作,并且也输出一些资讯啰! testfile=/dev/shm/netstat_checking.txt netstat -tuln > ${testfile} # 先转存资料到记忆体当中!不用一直执行netstat testing=$(grep ":80 " ${testfile}) # 侦测看port 80 在否? if [ "${testing}" != "" ]; then echo "WWW is running in your system." fi testing=$(grep ":22 " ${testfile}) # 侦测看port 22 在否? if [ "${testing}" != "" ]; then echo "SSH is running in your system." fi testing=$(grep ":21 " ${testfile}) # 侦测看port 21 在否? if [ "${testing}" != "" ]; then echo "FTP is running in your system." fi testing=$(grep ":25 " ${testfile}) # 侦测看port 25 在否? if [ "${testing}" != "" ]; then echo "Mail is running in your system." fi
#!/bin/bash # Program: # You input your demobilization date, I calculate how many days before you demobilize. # History: # 2015/07/16 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH
# 1. 告知使用者这支程式的用途,并且告知应该如何输入日期格式? echo "This program will try to calculate :" echo "How many days before your demobilization date..." read -p "Please input your demobilization date (YYYYMMDD ex>20150716): " date2
# 2. 测试一下,这个输入的内容是否正确?利用正规表示法啰~ date_d=$(echo ${date2} |grep '[0-9]\{8\}') # 看看是否有八个数字 if [ "${date_d}" == "" ]; then echo "You input the wrong date format...." exit 1 fi
# 3. 开始计算日期啰~ declare -i date_dem=$(date --date="${date2}" +%s) # 退伍日期秒数 declare -i date_now=$(date +%s) # 现在日期秒数 declare -i date_total_s=$((${date_dem}-${date_now})) # 剩余秒数统计 declare -i date_d=$((${date_total_s}/60/60/24)) # 转为日数 if [ "${date_total_s}" -lt "0" ]; then # 判断是否已退伍 echo "You had been demobilization before: " $((-1*${date_d})) " ago" else declare -i date_h=$(($((${date_total_s}-${date_d}*60*60*24))/60/60)) echo "You will demobilize after ${date_d} days and ${date_h} hours." fi
#!/bin/bash # Program: # Show "Hello" from $1.... by using case .... esac # History: # 2015/07/16 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH
case ${1} in "hello") echo "Hello, how are you ?" ;; "") echo "You MUST input parameters, ex> {${0} someword}" ;; *) # 其实就相当于万用字元,0~无穷多个任意字元之意! echo "Usage ${0} {hello}" ;; esac
#!/bin/bash # Program: # Use function to repeat information. # History: # 2015/07/17 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH
function printit(){ echo -n "Your choice is " # 加上-n 可以不断行继续在同一行显示 }
echo "This program will print your selection !" case ${1} in "one") printit ; echo ${1} | tr 'az' 'AZ' # 将参数做大小写转换! ;; "two") printit ; echo ${1} | tr 'az' 'AZ' ;; "three") printit ; echo ${1} | tr 'az' 'AZ' ;; *) echo "Usage ${0} {one|two|three}" ;; esac
#!/bin/bash # Program: # Use function to repeat information. # History: # 2015/07/17 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH
function printit(){ echo "Your choice is ${1}" # 这个$1 必须要参考底下指令的下达 }
echo "This program will print your selection !" case ${1} in "one") printit 1 # 请注意, printit 指令后面还有接参数! ;; "two") printit 2 ;; "three") printit 3 ;; *) echo "Usage ${0} {one|two|three}" ;; esac
12.5 循环
12.5.1 while do done、until
do done(不定循环)
语法:
1 2 3 4
while [ condition ] <==中括号内的状态就是判断式 do <==do 是循环的开始! 程式段落 done
1 2 3 4
until [ condition ] do 程式段落 done
示例:
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/bin/bash # Program: # Repeat question until user input correct answer. # History: # 2015/07/17 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH
while [ "${yn}" != "yes" -a "${yn}" != "YES" ] do read -p "Please input yes/YES to stop this program: " yn done echo "OK! you input the correct answer."
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/bin/bash # Program: # Repeat question until user input correct answer. # History: # 2015/07/17 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH
until [ "${yn}" == "yes" -o "${yn}" == "YES" ] do read -p "Please input yes/YES to stop this program: " yn done echo "OK! you input the correct answer."
示例:(计算1+2+3+....+100)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/bin/bash # Program: # Use loop to calculate "1+2+3+...+100" result. # History: # 2015/07/17 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH
s=0 # 这是加总的数值变数 i=0 # 这是累计的数值,亦即是1, 2, 3.... while [ "${i}" != "100" ] do i=$(($i+1)) # 每次i 都会增加1 s=$(($s+$i)) # 每次都会求和一次 done echo "The result of '1+2+3+...+100' is ==> $s"
12.5.2 for...do...done(固定循环)
语法:
1 2 3 4
for var in con1 con2 con3 ... do 程式段 done
示例:
1 2 3 4 5 6 7 8 9 10 11 12
#!/bin/bash # Program: # Using for .... loop to print 3 animals # History: # 2015/07/17 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH
for animal in dog cat elephant do echo "There are ${animal}s.... " done
示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!/bin/bash # Program # Use ping command to check the network's PC state. # History # 2015/07/17 VBird first release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH network="192.168.1" # 先定义一个网域的前面部分! for sitenu in $(seq 1 100) # seq 为sequence(连续) 的缩写之意 do # 底下的程式在取得ping 的回传值是正确的还是失败的! ping -c 1 -w 1 ${network}.${sitenu} &> /dev/null && result=0 || result=1 # 开始显示结果是正确的启动(UP) 还是错误的没有连通(DOWN) if [ "${result}" == 0 ]; then echo "Server ${network}.${sitenu} is UP." else echo "Server ${network}.${sitenu} is DOWN." fi done
#!/bin/bash # Program: # User input dir name, I find the permission of files. # History: # 2015/07/17 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH
# 1. 先看看这个目录是否存在啊? read -p "Please input a directory: " dir if [ "${dir}" == "" -o ! -d "${dir}" ]; then echo "The ${dir} is NOT exist in your system." exit 1 fi
# 2. 开始测试档案啰~ filelist=$(ls ${dir}) # 列出所有在该目录下的档案名称 for filename in ${filelist} do perm="" test -r "${dir}/${filename}" && perm="${perm} readable" test -w "${dir}/${filename}" && perm="${perm} writable" test -x "${dir}/${filename}" && perm="${perm} executable" echo "The file ${dir}/${filename}'s permission is ${perm} " done
12.5.3 for...do...done
的数值处理
语法:
1 2 3 4
for ((初始值;限制值;赋值运算)) do 程式段 done
示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/bin/bash # Program: # Try do calculate 1+2+....+${your_input} # History: # 2015/07/17 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH
read -p "Please input a number, I will count for 1+2+...+your_input: " nu
s=0 for (( i=1; i<=${nu}; i=i+1 )) do s=$((${s}+${i})) done echo "The result of '1+2+3+...+${nu}' is ==> ${s}"
#!/bin/bash # Program: # Try do tell you what you may eat. # History: # 2015/07/17 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH
范例一:测试dir_perm.sh 有无语法的问题? [dmtsai@study ~]$ sh -n dir_perm.sh # 若语法没有问题,则不会显示任何资讯!
范例二:将show_animal.sh 的执行过程全部列出来~ [dmtsai@study ~]$ sh -x show_animal.sh + PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin + export PATH + for animal in dog cat elephant + echo 'There are dogs.... ' There are dogs.... + for animal in dog cat elephant + echo 'There are cats.... ' There are cats.... + for animal in dog cat elephant + echo 'There are elephants.... ' There are elephants....
范例一:请root 给予vbird2 密码 # passwd vbird2 Changing password for user vbird2. New UNIX password: <==这里直接输入新的密码,萤幕不会有任何反应 BAD PASSWORD: The password is shorter than 8 characters <==密码太简单或过短的错误! Retype new UNIX password: <==再输入一次同样的密码 passwd: all authentication tokens updated successfully . <==竟然还是成功修改了!
范例一:列出系统上面有启动的unit [root@study ~]# systemctl UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_mis... loaded active waiting Arbitrary Executable File Formats File System sys-devices-pc...:0:1:... loaded active plugged QEMU_HARDDISK sys-devices-pc...0:1-0... loaded active plugged QEMU_HARDDISK sys-devices-pc...0:0-1... loaded active plugged QEMU_DVD-ROM .....(中间省略)..... vsftpd.service loaded active running Vsftpd ftp daemon .....(中间省略)..... cups.socket loaded failed failed CUPS Printing Service Sockets .....(中间省略)..... LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, ie generalization of SUB. SUB = The low-level unit activation state, values depend on unit type.
141 loaded units listed. Pass --all to see loaded but inactive units, too. To show all installed unit files use 'systemctl list-unit-files'. # 列出的项目中,主要的意义是: # UNIT :项目的名称,包括各个unit 的类别(看副档名) # LOAD :开机时是否会被载入,预设systemctl 显示的是有载入的项目而已喔! # ACTIVE :目前的状态,须与后续的SUB 搭配!就是我们用systemctl status 观察时,active 的项目! # DESCRIPTION :详细描述啰 # cups 比较有趣,因为刚刚被我们玩过,所以ACTIVE 竟然是failed 的喔!被玩死了!^_^ # 另外,systemctl 都不加参数,其实预设就是list-units 的意思!
范例二:列出所有已经安装的unit 有哪些? [root@study ~]# systemctl list-unit-files UNIT FILE STATE proc-sys-fs-binfmt_misc.automount static dev-hugepages.mount static dev-mqueue.mount static proc-fs-nfsd.mount static .....(中间省略)..... systemd-tmpfiles-clean.timer static
[root@study ~]# systemctl daemon-reload [root@study ~]# systemctl start backup.service [root@study ~]# systemctl status backup.service backup.service - backup my server Loaded: loaded (/etc/systemd/system/backup.service; disabled) Active: inactive (dead)
Aug 13 07:50:31 study.centos.vbird systemd[1]: Starting backup my server... Aug 13 07:50:31 study.centos.vbird bash[20490]: job 8 at Thu Aug 13 07:50:00 2015 Aug 13 07:50:31 study.centos.vbird systemd[1]: Started backup my server. # 为什么Active 是inactive 呢?这是因为我们的服务仅是一个简单的script 啊! # 因此执行完毕就完毕了,不会继续存在记忆体中喔!
# 3. 本程式的执行结果,必须输入姓名、360 度角的角度值来计算: [root@study ~]# ./main Please input your name: VBird <==这里先输入名字 Please enter the degree angle (ex> 90): 30 <==输入以360 度角为主的角度 Hi, Dear VBird, nice to meet you. <==这三行为输出的结果喔! The Sin is: 0.50 The Cos is: 0.87
范例三:列出logrotate 这个软体的相关说明资料: [root@study ~]# rpm -qi logrotate Name : logrotate # 软体名称 Version : 3.8.6 # 软体的版本 Release : 4.el7 # 释出的版本 Architecture: x86_64 # 编译时所针对的硬体等级 Install Date: Mon 04 May 2015 05:52:36 PM CST # 这个软体安装到本系统的时间 Group : System Environment/Base # 软体是放再哪一个软体群组中 Size : 102451 # 软体的大小 License : GPL+ # 释出的授权方式 Signature : RSA/SHA256, Fri 04 Jul 2014 11:34:56 AM CST, Key ID 24c6a8a7f4a80eb5 Source RPM : logrotate-3.8.6-4.el7.src.rpm # 这就是SRPM 的档名 Build Date : Tue 10 Jun 2014 05:58:02 AM CST # 软体编译打包的时间 Build Host : worker1.bsys.centos.org # 在哪一部主机上面编译的 Relocations : (not relocatable) Packager : CentOS BuildSystem <http://bugs.centos.org> Vendor : CentOS URL : https://fedorahosted.org/logrotate/ Summary : Rotates, compresses, removes and mails system log files Description : # 这个是详细的描述! The logrotate utility is designed to simplify the administration of log files on a system which generates a lot of log files. Logrotate allows for the automatic rotation compression, removal and mailing of log files. Logrotate can be set to handle a log file daily, weekly, monthly or when the log file gets to a certain size. Normally, logrotate runs as a daily cron job.
Install the logrotate package if you need a utility to deal with the log files on your system. # 列出该软体的information (资讯),里面的资讯可多著呢,包括了软体名称、 # 版本、开发商、SRPM档案名称、打包次数、简单说明资讯、软体打包者、 # 安装日期等等!如果想要详细的知道该软体的资料,用这个参数来了解一下
范例一:搜寻磁碟阵列(raid) 相关的软体有哪些? [root@study ~]# yum search raid Loaded plugins: fastestmirror, langpacks # yum 系统自己找出最近的yum server Loading mirror speeds from cached hostfile # 找出速度最快的那一部yum server * base: ftp.twaren.net # 底下三个软体库,且来源为该伺服器! * extras: ftp.twaren.net * updates: ftp.twaren.net ....(前面省略).... dmraid-events-logwatch.x86_64 : dmraid logwatch-based email reporting dmraid-events.x86_64 : dmevent_tool (Device-mapper event tool) and DSO iprutils.x86_64 : Utilities for the IBM Power Linux RAID adapters mdadm.x86_64 : The mdadm program controls Linux md devices (software RAID arrays) ....(后面省略).... # 在冒号(:) 左边的是软体名称,右边的则是在RPM 内的name 设定(软体名) # 瞧!上面的结果,这不就是与RAID 有关的软体吗?如果想了解mdadm 的软体内容呢?
范例二:找出mdadm 这个软体的功能为何 [root@study ~]# yum info mdadm Installed Packages <==这说明该软体是已经安装的了 Name : mdadm <==这个软体的名称 Arch : x86_64 <==这个软体的编译架构 Version : 3.3.2 <==此软体的版本 Release : 2.el7 <==释出的版本 Size : 920 k <==此软体的档案总容量 Repo : installed <==软体库回报说已安装的 From repo : anaconda Summary : The mdadm program controls Linux md devices (software RAID arrays) URL : http://www.kernel.org/pub/linux/utils/raid/mdadm/ License : GPLv2+ Description : The mdadm program is used to create, manage, and monitor Linux MD (software : RAID) devices. As such, it provides similar functionality to the raidtools : package. However, mdadm is a single program, and it can perform : almost all functions without a configuration file, though a configuration : file can be used to help with some common tasks. # 不要跟我说,上面说些啥?自己找字典翻一翻吧!拜托拜托!
范例五:列出提供passwd 这个档案的软体有哪些 [root@study ~]# yum provides passwd passwd-0.79-4.el7.x86_64 : An utility for setting or changing passwords using PAM Repo : base
passwd-0.79-4.el7.x86_64 : An utility for setting or changing passwords using PAM Repo : @anaconda # 找到啦!就是上面的这个软体提供了passwd 这个程式!
Installed size: 528 k Is this ok [y/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Erasing : pam-devel-1.1.8-12.el7_1.1.x86_64 1/1 Verifying : pam-devel-1.1.8-12.el7_1.1.x86_64 1/1