《Linux操作系统》教案(9)

2019-08-29 22:08

route

route -n 查看路由状态

route del -net 网络ip netmask 子网掩码 dev 网络接口名 删除一条路由

route add -net 网络ip netmask 子网掩码 dev 网络接口名 添加一条路由

route add default gw 默认网关ip 添加一个默认网关

ip

ip link show

显示系统中所有网络接口信息

ip -s link show eth0 显示网络接口eth0的信息

ip link set eth0 up 启动网络接口eth0

ip link set eth0 down

关闭网络接口eth0

ip link set eth0 name whpuser

设置网络接口eth0的名称为whpuser,这条命令执行完后,务必改回原来的状态,即 ip link set whpuser name eth0

ip assress show

显示地址

ip address add 192.168.50.50/24 broadcast + dev eth0 label eth0:whpu 为网络接口eth0设置另外一个IP,该IP对应的接口为eth0:whpu,要删除这个添加的ip可以使用:ip address del 192.168.50.50/24 dev eth0

ip route show 显示路由信息

41

host

host www.whpu.edu.cn

查看www.whpu.edu.cn的ip地址

nslookup

nslookup www.whpu.edu.cn 和host的功能大致相同。

6 Shell Script

bash shell语法基础

sh-bang行 注释 通配符或元字符 #!/bin/bash 用来告诉内核使用哪种shell执行本脚本 # This is a comment 注释文本前添加# *,?,[],<,>,>>,|等这些字符在shell中具有特殊意义,如果需要使用它们的字面义,需要使用反斜杠或配对引号对其转义。 echo ?How are you?? printf ?%s\\n? ?How are you?? 作用域在当前shell中。当一个脚本执行结束,它们就不再可用。 variable_name=value 显示输出 局部变量

42

declare variable_name=value name=?John Doe? let x=5 全局变量 全局变量也称为环境变量,它们由export命令创建。作用域在当前shell以及shell派生的子进程中,当脚本退出,全局作用域失效。 export VARIABLE_NAME=value declare -x VARIABLE_NAME=value export PATH=$PATH:/home/user/bin 使用美元符号$从变量中提取值 echo $variable_name echo $PATH 接受用户输入到脚本 echo ?What is your name?? read name echo ?Hello? $name 从命令行传递参数给脚本 命令行 $ scriptname arg1 arg2 arg3 … 在脚本里 echo $1 $2 $3 位置参数 echo $* 所有位置参数 echo $# 位置参数个数 declare -a array_name=(word1 word2 …) echo ${array_name[0]} 当需要将shell命令执行的结果赋给一个变量,那么就需要进行命令替换。 variable_name=`command` variable_name=$(command) 使用(())语法或let命令。 let a=0 let b=1 let c=$a+$b+1 d=$((a+b+c+1)) printf \printf \printf \运算符包括算术运算符和关系运算符 bc命令可以用来进行表达式运算,在shell命令提示符下输入bc后,将会等待用户的输入。例如,依次输入以下表达式: 提取变量值 读取用户输入 参数 数组 命令替换 算术运算 运算符

43

每输入一个表达式后,回车,即会在喜表达式下得到一个结果。例如,输入5-2,会得到结果3;输入5<2会得到结果0(表示false);输入5!=10会得到结果1(表示true)。 关系测试 使用测试命令test或[],用于数值关系运算测试 -eq 等于 -ne 不等于 if test 5 -eq 6 if [5 -eq 6] if test 5 -ne 6 if [5 -ne 6] -lt 小于 if test 5 -lt 6 if [5 -lt 6] -le 小于等于 if test 5 -le 6 if [5 -le 6] -gt 大于 if test 5 -gt 6 if [5 -gt 6] -ge 大于等于 if test 5 -ge 6 if [5 -ge 6] 文件测试 用于判断文件的类型或模式 -s file 为非空文件时为真 -f file -d file -w file -r file -x file 字符串判断 为一般文件而不是目录时为真 为目录而不是文件时为真 为可写文件时为真 为只读文件时为真 为可执行文件为真 用于判定字符串是否为空或相等 -z string string为空时判定为真 -n string string不为空时判定为真 string1!=string2 不相等为真 string1=string2 相等为真 条件表达式组合 有多个条件组合进行判定 !expression expression1 expression2 expression1 expression2 取表达式值的反 -a AND组合; -o OR组合; if condition then fi condition判断为真;或者condition代表的命令执行返回状态值为0时执行。 #!/bin/bash if cat $1 then echo -e \echoed\fi

44

#!/bin/bash if test $1 -gt 0 then echo \fi if condition then else fi #!/bin/bash if [ $# -eq 0 ] then echo \: You must give/supply one integers\exit 1 fi if test $1 -gt 0 then echo \else echo \fi osch=0 echo \echo \echo -n \read osch if [ $osch -eq 1 ] ; then echo \else if [ $osch -eq 2 ] ; then echo \ else echo \you don't like Unix/Linux OS.\ fi fi if condition #!/bin/bash then if [ $1 -gt 0 ] then elif condition1 echo \then elif [ $1 -lt 0 ] then elif condition2 echo \then elif [ $1 -eq 0 ] then else echo \ else fi echo \fi

45


《Linux操作系统》教案(9).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:学校物价申请报告

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: