
linux的习题答案.docx
25页linux的习题答案 几个实践课题 1、Tenny需要修改命令提示符,在当前工作目录为“/usr/bin”的时候显示:[bin]$ 当前工作目录“/usr/local/sbin”的时候显示:[sbin]$ 2、编写一个shell脚本,从键盘读入5个数然后显示最大数,最小数以及平均数 3、编写一个shelll脚本,显示Fibonacci数列的前20项例如0,1,1,2,3,5,8,13,21....... 4、编写一个shell脚本,从键盘上接收两个文件名,如果两个文件都存在则交换两个文件的内容,否则给出错误信息 参考答案: 1.,export PS1="[\$(basename \$PWD)]" 2., #!/bin/bash total=5 i=1 sum=0 while [ $i -le $total ] do echo "$i: input a number" read num if [ $i -eq 1 ] then min=$num max=$num fi if [ $min -gt $num ] then min=$num fi if [ $max -lt $num ] then max=$num fi let sum+=num let i++ done let average=sum/total echo "Min $min, Max $max, Average $average" 3., #!/bin/bash fib[0]=0 fib[1]=1 first=0 second=1 i=2 while [ $i -lt 20 ] do let fib[$i]=first+second first=$second second=${fib[$i]} let i++ done i=0 while [ $i -lt 20 ] do echo -n "${fib[$i]} " let i++ done echo "" 4., #!/bin/bash echo "file 1 name:" read file1 echo "file 2 name:" read file2 if [ -f $file1 -a -f $file2 ] then mv $file1 /tmp/$file2.$$ mv $file2 $file1 mv /tmp/$file2.$$ $file2 else echo "error" fi 其它的LINUX习题 核心的许可证是什么(选择最合适的答案) a. NDA b. GDP c. GPL d. GNU 2.谁是Linux的创始人(选择最合适的答案) a. Turbolinux b. AT&T Bell Laboratry c. University of Helsinki d. Linus Torvalds 是操作系统,意味着开放性源码是自由可用。
选择最合适的答案) a、封闭资源 b、开放资源 c、用户注册 d、开放性二进制 4.确定myfile的文件类型的命令是什么(选择最合适的答案) a. type myfile b. type -q myfile c. file myfile d. whatis myfile 5.用来分离目录名和文件名的字符是什么(选择最合适的答案) a. slash (/) b. period (.) c. dash (-) d. asterisk (*) 6.你想显示文件"longfile"的最后10行,下面那个命令是正确的(选择最合适的答案) a、tail logfile b、head -10 longfile c、taid -d 10 longfile d、head longfile 7.假如你得到一个运行命令被拒绝的信息,你可以用哪个命令去修改它的权限使之可以正常运行(选择最合适的答案) a. path= b. chmod c. chgrp d. chown 8.拷贝mydir\myfile文件到dir2目录下,但是系统提示这个文件已经存在,下面那个命令是正确的(选择最合适的答案) a、cp -w mydir\myfile dir2 b、cp -i mydir\myfile dir2 c、cp mydir\myfile dir2 d、cp -v mydir\myfile dir2 10.假如文件是按8进制来定义,下面那个值代表了读和写(选择最合适的答案) a、2 b、6 c、4 d、1 临时目录一般存在下面那个文件夹中(选择最合适的答案) a、/tmp b、/proc c、/data d、/dev 12.一个文件的权限是-rw-rw-r--,这个文件所有者的权限是什么(选择最合适的答案) a、read-only b、read-write c、write 14.下面哪个文件代表系统初始化信息(选择最合适的答案) a、/etc/inittab b、/etc/init c、/etc/proc d、/etc/initproc 15.哪条命令从当前系统切换到启动级别1(选择最合适的答案) a、inittab 1 b、init 1 c、level 1 d、rlevel1 16.下面哪个选项能取消shutdown命令(选择最合适的答案) a、shutdown -c b、shutdown -x c、shutdown -u d、shutdown -n 17.通过shell执行一个命令,必须先敲入一个_____(选择最合适的答案) a. 参数 b. 命令 c. 操作符 d. 终端ID号 18.哪个符号加在命令后面可以在后台执行程序(选择最合适的答案) a. @ b. & c. # d. * 19.在vi编辑器里,哪个命令能将光标移到第200行(选择最合适的答案) a. 200g b. :200 c. g200 d. G200 20.用vi打开一个文件,如何用字母”new”来代替字母”old”(选择最合适的答案) a. :r/old/new b. :s/old/new c. :1,$s/old/new/g d. :s/old/new/g 23.你给公司的新同事添加一个用户,你起初指定他的帐号在30天后过期,现在想改变这个过期时间,用下面哪个命令(选择最合适的答案) a、usermod -a b、usermod -d c、usermod -x d、usermod -e 24.用下面哪个命令可以不用退出vi编辑器来切换文件(选择最合适的答案) a. :e for edit command b. map command c. export command d. set command 25.下面哪个选项用来添加用户定义用户登录的shell(选择最合适的答案) a、-s b、-u c、-l d、-sh 26.如果你想给变量"IQ"定义为4,下面哪些时正确的(选择最合适的答案) a、IQ=4 b、set IQ=4 c、set $IQ=4 d、IQ set 4 28.哪一个命令能用来查找在文件TESTFILE中只包含四个字符的行(选择最合适的答案) '' TESTFILE '....' TESTFILE '^$' TESTFILE '^....$' TESTFILE 29.哪一个命令能用来删除当前目录及其子目录下名为‘core'的文件(选择最合适的答案) . -name core -exec rm ; . -name core -exec rm {} \ ; . -name core -exec rm {} -; . -name core -exec rm {} ; 31.用标准的输出重定向(>)像"> file01"能使文件file01的数据_____(选择最合适的答案) a. 被复制 b. 被移动 c. 被覆盖 d. 被打印 32.按_____键能中止当前运行的命令。
选择最合适的答案) a. Ctrl-D b. Ctrl-C c. Ctrl-B d. Ctrl-F 33.下面对Linux命令的描述哪个是正确的(选择最合适的答案) a. 不是大小写敏感的 b. 都是大写的 c. 大小写敏感 d. 都是小写 34.在vi编辑器里,命令”dd”用来删除当前(选择最合适的答案) a. 字 b. 字符 c. 变量 d. 行 37.下面哪个命令能去掉主引导信息里的内容(选择最合适的答案) a、fdisk /mbr b、format /mbr c、mbr/format d、mbr/replace 38.下面哪条命令可以显示交换内存(选择最合适的答案) a、showmem b、freemem c、swap d、free 40.下面哪段定义了添加一个tar文件的信息(选择最合适的答案) a、use the append command b、use the add comm。












