Linux系统实验指导书.doc_第1页
Linux系统实验指导书.doc_第2页
Linux系统实验指导书.doc_第3页
Linux系统实验指导书.doc_第4页
Linux系统实验指导书.doc_第5页
已阅读5页,还剩25页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Linux系统实验指导书目录实验一 Linux操作系统基本操作2实验二 Linux常用命令5实验三 Linux下文件编辑7实验四 Shell基本编程方法9实验五 Shell高级编程方法11实验六 Linux系统编程基础18实验七 文件系统实验21实验八 Linux进程管理实验22实验九 Linux进程通信实验23实验一 Linux操作系统基本操作一、实验目的 通过本实验掌握telnet客户端的使用,登录到远程主机,熟悉文件系统的基本命令。二、实验内容需掌握的基本命令包含: passwd、pwd、cd、mkdir、rm、rmdir、ls、cp、cat、head、tail、mv 等。三、实验准备了解telnet的原理和使用方法。了解上述基本命令的功能。四、实验步骤1. 用telnet客户端登录到主机2. 用passwd命令修改自己的口令3. 用pwd命令察看自己的主目录($HOME)4. 用mkdir在自己的主目录($HOME)建立名为“psdir”的目录5. 用cd命令把当前目录改为“$HOME/psdir”6. 用cp 命令把 “/etc/passwd” 文件拷贝到 “$HOME/psdir”目录7. 用ls, cat, head, tail 观察 “$HOME/psdir”目录下的 passwd文件8. 用cp 命令将passwd复制一份为passwd29. 用mv命令将passwd2移动到$HOME下10. 用rm 命令删除“$HOME/psdir”目录下的 passwd 文件11. 用rmdir删除 psdir目录五、实验报告要求用自己的账号登录并描述上诉命令运行的结果。六、参考实例C: telnet CentOS release 5.4 (Final)Kernel 2.6.18-164.15.1.el5PAE on an i686login:j7c99Password:Welcome To CS Linux Server |/ - - / ( )oOOo-(_)-oOOo ,._ 贵州大学计算机科学系 ( _. )a, _, _ /,-, Linux 实验服务器 )-. / )&, ._ , 请勿用于非法用途! _( . Oooo ._. oooO ( ) ( ) ) / ( (_/ _)#-bash-3.2$ passwdChanging password for user j7c99.Changing password for j7c99(current) UNIX password: New UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully.-bash-3.2$ pwd/students/j7/j7c99-bash-3.2$ mkdir psdir-bash-3.2$ cd psdir-bash-3.2$ pwd/students/j7/j7c99/psdir-bash-3.2$ cp /etc/passwd .-bash-3.2$ ls -l总计 144-rw-r-r- 1 j7c99 students 135519 04-13 21:13 passwd-bash-3.2$ cat passwd-bash-3.2$ head passwd-bash-3.2$ tail passwd-bash-3.2$ cp passwd passwd2-bash-3.2$ ls -l总计 288-rw-r-r- 1 j7c99 students 135519 04-13 21:13 passwd-rw-r-r- 1 j7c99 students 135519 04-13 21:14 passwd2-bash-3.2$ mv passwd2 /-bash-3.2$ ls -l .总计 168drwx- 2 j7c99 students 4096 03-14 00:27 mail-rw-r-r- 1 j7c99 students 135519 04-13 21:14 passwd2drwxr-xr-x 2 j7c99 students 4096 04-13 21:14 psdirdrwxr-xr-x 2 j7c99 students 4096 03-13 00:24 public_html-bash-3.2$ rm passwd-bash-3.2$ ls-bash-3.2$ pwd/students/j7/j7c99/psdir-bash-3.2$ cd .-bash-3.2$ rmdir psdir-bash-3.2$ ls -l总计 160drwx- 2 j7c99 students 4096 03-14 00:27 mail-rw-r-r- 1 j7c99 students 135519 04-13 21:14 passwd2drwxr-xr-x 2 j7c99 students 4096 03-13 00:24 public_html-bash-3.2$ 实验二 Linux常用命令一、实验目的 通过本实验掌握Linux环境下常用命令。二、实验内容需掌握的基本命令包含: chmod、man、date、df、file、id、ps、mail、write 等三、实验准备了解上述基本命令的功能。四、实验步骤1. 用telnet客户端登录到主机2. 拷贝 /etc/motd 文件到自己的主目录下3. 用 ls l 查看主目录下的 motd 文件权限 4. 用chmod命令给motd文件去掉r、w权限,再用 ls l 查看5. 用chmod命令给motd文件加上534权限,再用ls l 查看6. 用man命令查看date命令参数,带各种参数运行date命令7. 用man命令查看df命令参数,带各种参数运行df命令8. 用man命令查看file命令参数,带各种参数运行file命令9. 用man命令查看ps命令参数,带各种参数运行ps命令10. 用mail给本机某用户发送邮件,并查看对方来信11. 用write给本机某用户发送信息12. 用logout、exit、Ctrl+d 方式退出登录五、实验报告要求用自己的账号登录并描述上诉命令运行的结果。六、参考实例-bash-3.2$ cp /etc/motd .-bash-3.2$ ls -l总计 8-rw-r-r- 1 j7c99 students 800 04-13 21:39 motd-bash-3.2$ chmod -r -w motd-bash-3.2$ ls -l总计 8- 1 j7c99 students 800 04-13 21:39 motd-bash-3.2$ chmod 534 motd-bash-3.2$ ls -l总计 8-r-x-wxr- 1 j7c99 students 800 04-13 21:39 motd-bash-3.2$-bash-3.2$ date2010年 04月 13日 星期二 21:40:24 CST-bash-3.2$ df文件系统 1K-块 已用 可用 已用% 挂载点/dev/hda1 19840892 6143040 12673712 33% /tmpfs 1974744 0 1974744 0% /dev/shm/dev/hda2 144189492 7253036 129612024 6% /students/dev/hda4 135429292 1629088 126920772 2% /home-bash-3.2$ file *motd: ISO-8859 C+ program text-bash-3.2$ ps PID TTY TIME CMD 9435 pts/0 00:00:00 bash 9549 pts/0 00:00:00 ps-bash-3.2$mail j7c99-bash-3.2$write j7c98-bash-3.2$logout-bash-3.2$exit实验三 Linux下文件编辑一、实验目的 通过本实验掌握Linux环境下vi编辑器的使用,以及简单的程序编写方法。二、实验内容使用vi编辑器编辑程序源文件,编译运行程序。三、实验准备了解vi编辑器命令行方式、编辑方式和末行命令方式。四、实验步骤1. 用telnet客户端登录到主机;2. 用vi编辑器编写一c语言程序,显示输出“my first linux c program!”,保存为testc.c,编译运行查看结果;3. 用vi编辑器编写一shell程序,显示输出“my first shell program!”,保存为 testshell.sh,运行查看结果;4. 拷贝 “/etc/passwd”到用户主目录为passwd2,并用vi编辑器打开;5. 用vi编辑器打开“passwd2”,找到自己登陆id以及root用户对应的行,删除其余各行,用“:x”保存修改退出;6. 用vi编辑器打开passwd2,使用dd、p移动root对应行到登陆id对应行下;7. 在vi编辑器中用“:! date”查看当前系统时间;8. 在vi编辑器中用“:r ! date”读取系统时间到当前编辑文件,用“:wq”存盘退出;9. 在vi编辑器里面打开刚才编辑的文件,用“:r /etc/motd”读入“/etc/motd”到当前编辑文件;10. 重复6的操作,使用“:q!”、“:q” 查看效果 五、实验报告要求用自己的账号登录并描述上诉命令运行的结果。六、参考实例-bash-3.2$ cat testc.cMain() printf(“my first linux c program!n”);-bash-3.2$ cat testc.c#!/bin/shecho -e my first shell program!n-bash-3.2$-bash-3.2$cp /etc/passwd /passwd2-bash-3.2$cd /-bash-3.2$vi passwd2-bash-3.2$实验四 Shell基本编程方法一、实验目的 通过本实验掌握Linux环境下shell程序设计的一般方法。二、实验内容需掌握shell程序编写的基本方法。三、实验准备了解shell基本语法。四、实验步骤1. 用telnet客户端登录到主机;2. 编写一shell程序,读取3个命令行参数并显示$0、$1$6、$#、$、$?、$*、$的具体值;源程序:testshell2.sh#!/bin/shecho 脚本文件名 :$0echo 第一到四参数 :$1 $2 $3 $4 echo 参数个数 :$# echo 所有命令行参数:$ echo 退出状态 :$?echo 所有命令行参数:$* echo 正在执行进程的进程ID(PID):$ -bash-3.2$ sh testshell.sh p1 p2 p3 p43. 使用if-then-else语句获取当前小时数并提示“上午”、“中午”、“下午”;源程序:iftime.sh# !/bin/shhour=date +%Hif $hour -le 11 then echo 早上elif $hour -ge 14 then echo 晚上else echo 中午fi4. 使用case语句获取当前小时数并提示“上午”、“中午”、“下午”;源程序:casetime.sh# !/bin/shhour=date +%H case $hour in01-9|101) echo 上午;1234) echo 中午;*) echo 下午;Esac5. 使用for循环输出显示 110 的平方源程序:forsquare.sh# !/bin/shfor i in seq 10dosq=expr $i * $iecho $sqdone6. 使用where循环输出显示 110 的平方源程序:wheresquare.sh# !/bin/shi=1while $i -le 10 dosq=expr $i * $iecho $sqi=expr $i + 1done7. 使用until循环输出显示 110 的平方 源程序:untilsquare.sh# !/bin/shi=1until $i -gt 10 dosq=expr $i * $iecho $sqi=expr $i + 1done五、实验报告要求用自己的账号登录并完成上述shell程序编写,实验报告包括程序源码和运行结果。六、参考实例-bash-3.2$ cat testshell2.sh#!/bin/shecho 脚本文件名 :$0echo 第一到四参数 :$1 $2 $3 $4 echo 参数个数 :$# echo 所有命令行参数:$ echo 退出状态 :$?echo 所有命令行参数:$* echo 正在执行进程的进程ID(PID):$ -bash-3.2$-bash-3.2$ sh testp.sh p1 p2 p3 p4脚本文件名 :testp.sh第一到四参数 :p1 p2 p3 p4参数个数 :4所有命令行参数:p1 p2 p3 p4退出状态 :0所有命令行参数:p1 p2 p3 p4正在执行进程的进程ID(PID):30559-bash-3.2$-bash-3.2$实验五 Shell高级编程方法一、实验目的 通过本实验掌握Linux环境下shell编写复杂程序。二、实验内容参考示例编写一通讯录程序;三、实验准备了解shell基本语法。四、实验步骤1. 用telnet客户端登录到主机;2. 查看所附示例程序;3. 使用 sh first 运行程序查看程序运行效果;4. 改写所有程序英文提示为中文;5. 个人信息中加入电子邮电字段。源程序:-bash-3.2$ cat first#!/bin/shtput cleartput cup 5 20echo COMMUNICATION OF FRIENDS echotput cup 9 15echo This is a small unix application echotput cup 12 15echo -n Please enter any key to continue. echoread answersh run-bash-3.2$ -bash-3.2$ cat run#!/bin/shechotput clearerror_flag=0while truedo if test $error_flag -eq 0 then tput clear tput cup 2 20;echo THE MAIN MENUecho tput cup 5 20;echo 0: EXIT this program echo tput cup 7 20;echo 1: EDIT MENU echo tput cup 9 20;echo 2: REPORTS MENU echo fitput cup 13 10;echo -n Enter your choice_read choicecase $choice in0) tput clear;exit 0;#echo run;1) sh EDIT;exit 0;2) sh REPORTS;*) sh ERROR;tput cup 20 1;tput ed;esacdoneerror_flag=1-bash-3.2$ -bash-3.2$ cat ADD#!/bin/shanswer=ywhile test $answer = y do tput clear tput cup 5 10;echo COMMUNICATION - ADD Mode echo tput cup 7 23;echo Name: tput cup 9 22;echo Address: tput cup 11 20;echo Telephone: tput cup 13 24;echo QQ: tput cup 7 30;read Name tput cup 9 31;read Address tput cup 11 32;read Telephone tput cup 13 28;read QQ echo $Name:$Address:$Telephone:$QQ: basicFile tput cup 15 10;echo -n Any more to add?(Y)es or (N)o_ read answer case $answer in Yy*) answer=y; *) answer=n; esac done tput clear-bash-3.2$ -bash-3.2$ cat DELETE#!/bin/shold_IFS=$IFSanswer=ywhile test $answer = ydo tput clear;tput cup 3 5;echo -n Enter the Name_ read response grep -i $response basicFile temp if test -s $temp then IFS=: read name address telephone QQ _ read answer if test $answer = y -o $answer = Y then grep -iv $name:$address:$telephone:$QQ basicFile basicFile fi else tput cup 7 10;echo $response not found fi tput cup 14 10;echo -n Any more to delete?(Y)es or (N)o_ read answer case $answer in Yy*) answer=y; *) answer=n; esacdoneIFS=$old_IFSrm tempexit 0-bash-3.2$ -bash-3.2$ cat DISPLAY#!/bin/shold_IFS=$IFSanswer=ywhile test $answer = ydo tput clear; tput cup 3 5;echo -n Enter the Name/QQ_ read response grep -i $response basicFile Temp if test -s $Temp then IFS=: read Name Address Telephone QQ _ read answer case $answer in Yy*) answer=y; *) answer=n; esac done IFS=$old_IFS rm Temp -bash-3.2$ -bash-3.2$ cat EDIT#!/bin/sherror_flag=0while true do if test $error_flag -eq 0 then tput clear;tput cup 5 10 echo COMMUNICATION EDIT Menu echo tput cup 7 20;echo 0: RETURN The Main Menu echo tput cup 9 20;echo 1: ADD echo tput cup 11 20;echo 2: UPDATESTATUS echo tput cup 13 20;echo 3: DISPLAY echo tput cup 15 20;echo 4: DELETE echo fi tput cup 17 10;echo -n Enter your choice_ read choice case $choice in 0) sh run;exit 0; 1) sh ADD; 2) sh UPDATE; 3) sh DISPLAY; 4) sh DELETE; *) sh ERROR tput cup 20 1;tput ed esacdoneerror_flag=1-bash-3.2$ -bash-3.2$ cat ERROR#!/bin/shtput cleartput cup 10 25echo Wrong Input.Try again. echotput cup 12 20echo -n Press any key to continue.read answerexit 0-bash-3.2$ -bash-3.2$ cat REPORTS#!/bin/shld_IFS=$IFS tput clear tput cup 2 10 ptemp;echo COMMUNICATION - REPORTS Mode ptemp echo ptemp cat basicFile tempIFS=:i=1while read name address telephone QQdoecho Name: $name ptempecho Address: $address ptempecho Telephone: $telephone ptempecho QQ: $QQ ptempecho ptempi=expr i+5done _read answerrm temp ptempIFS=$old_IFSexit 0-bash-3.2$ -bash-3.2$ cat UPDATE#!/bin/shold_IFS=IFSanswer=ywhile test $answer = ydo newa= ;newt= ;newq= tput clear tput cup 3 5;echo -n Enter the Name_ read response tput clear grep -i $response basicFile temp if test -s $temp then IFS=: read name address telephone QQ _ read newa tput cup 13 20;echo -n The new Address is: $newa tput cup 15 20;echo -n update the Telephone_ read newt tput cup 16 20;echo -n The new Telephone is: $newt tput cup 18 20;echo -n update the QQ_ read newq tput cup 19 20;echo -n The new QQ is: $newq echo $name:$newa:$newt:$newq temp1 grep -iv $name:$address:$telephone:$QQ basicFile temp1 grep -iv $name:$address:$telephone:$QQ temp1 basicFile rm temp1 else tput cup 7 10;echo $response not found fi tput cup 20 25;echo -n Any more to Update?(Y)es or(N)o_ read answer1 case $answer1 in Yy*) answer=y; *) answer=n; esacdoneIFS=$old_IFSrm tempexit 0五、实验报告要求用自己的账号登录并完成上述shell程序编写,实验报告包括程序源码和运行结果。六、参考实例-bash-3.2$ cat first#!/bin/shtput cleartput cup 5 20echo COMMUNICATION OF FRIENDS echotput cup 9 15echo This is a small unix application echotput cup 12 15echo -n Please enter any key to continue. echoread answersh run-bash-3.2$ -bash-3.2$ cat run#!/bin/shechotput clearerror_flag=0while truedo if test $error_flag -eq 0 then tput clear tput cup 2 20;echo THE MAIN MENUecho tput cup 5 20;echo 0: EXIT this program echo tput cup 7 20;echo 1: EDIT MENU echo tput cup 9 20;echo 2: REPORTS MENU echo fitput cup 13 10;echo -n Enter your choice_read choicecase $choice in0) tput clear;exit 0;#echo run;1) sh EDIT;exit 0;2) sh REPORTS;*) sh ERROR;tput cup 20 1;tput ed;esacdoneerror_flag=1-bash-3.2$ -bash-3.2$ cat ADD#!/bin/shanswer=ywhile test $answer = y do tput clear tput cup 5 10;echo COMMUNICATION - ADD Mode echo tput cup 7 23;echo Name: tput cup 9 22;echo Address: tput cup 11 20;echo Telephone: tput cup 13 24;echo QQ: tput cup 7 30;read Name tput cup 9 31;read Address tput cup 11 32;read Telephone tput cup 13 28;read QQ echo $Name:$Address:$Telephone:$QQ: basicFile tput cup 15 10;echo -n Any more to add?(Y)es or (N)o_ read answer case $answer in Yy*) answer=y; *) answer=n; esac done tput clear-bash-3.2$ -bash-3.2$ cat DELETE#!/bin/shold_IFS=$IFSanswer=ywhile test $answer = ydo tput clear;tput cup 3 5;echo -n Enter the Name_ read response grep -i $response basicFile temp if test -s $temp then IFS=: read name address telephone QQ _ read answer if test $answer = y -o $answer = Y then grep -iv $name:$address:$telephone:$QQ basicFile basicFile fi else tput cup 7 10;echo $response not found fi tput cup 14 10;echo -n Any more to delete?(Y)es or (N)o_ read answer case $answer in Yy*) answer=y; *) answer=n; esacdoneIFS=$old_IFSrm tempexit 0-bash-3.2$ -bash-3.2$ cat DISPLAY#!/bin/shold_IFS=$IFSanswer=ywhile test $answer = ydo tput clear; tput cup 3 5;echo -n Enter the Name/QQ_ read response grep -i $response basicFile Temp if test -s $Temp then IFS=: read Name Address Telephone QQ _ read answer case $answer in Yy*) answer=y; *) answer=n; esac done IFS=$old_IFS rm Temp -bash-3.2$ -bash-3.2$ cat EDIT#!/bin/sherror_flag=0while true do if test $error_flag -eq 0 then tput clear;tput cup 5 10 echo COMMUNICATION EDIT Menu echo tput cup 7 20;echo 0: RETURN The Main Menu echo tput cup 9 20;echo 1: ADD echo tput cup 11 20;echo 2: UPDATESTATUS echo tput cup 13 20;echo 3: DISPLAY echo tput cup 15 20;echo 4: DELETE echo fi tput cup 17 10;echo -n Enter your choice_ read choice case $choice in 0) sh run;exit 0; 1) sh ADD; 2) sh UPDATE; 3) sh DISPLAY; 4) sh DELETE; *) sh ERROR tput cup 20 1;tput ed esacdoneerror_flag=1-bash-3.2$ -bash-3.2$ cat ERROR#!/bin/shtput cleartput cup 10 25echo Wrong Input.Try again. echotput cup 12 20echo -n Press any key to continue.read answerexit 0-bash-3.2$ -bash-3.2$ cat REPORTS#!/bin/shold_IFS=$IFS tput clear tput cup 2 10 ptemp;echo COMMUNICATION - REPORTS Mode ptemp echo ptemp cat basicFile tempIFS=:i=1while read name address telephone QQdoecho Name: $name ptempecho Address: $address ptempecho Telephone: $telephone ptempecho QQ: $QQ ptempecho ptempi=expr i+5done _read answerrm temp ptempIFS=$old_IFSexit 0-bash-3.2$ -bash-3.2$ cat UPDATE#!/bin/shold_IFS=IFSanswer=ywhile test $answer = ydo newa= ;newt= ;newq= tput clear tput cup 3 5;echo -n Enter the Name_ read response tput clear grep -i $response basicFile temp if test -s $temp t

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论