打印

[原创] 实验4、练习使用Linux基本命

本主题被作者加入到个人文集中

实验4、练习使用Linux基本命


一、实验目标:
练习cp命令、mv命令、rm命令、mkdir命令、rmdir 命令、cd 命令 、pwd 命令、ls 命令、head命令、tail命令、touch命令、less命令的使用方法。

二、实验环境:
实验环境同实验1
三、实验步骤:
1、使用mkdir命令在家目录中建立目录:test1……test5
[zpeicn@x-study-as4 ~]$ mkdir test1 test2 test3 test4 test5
2、使用cd命令进入test1目录,并用pwd验证当前所在目录
[zpeicn@x-study-as4 ~]$ cd test1
[zpeicn@x-study-as4 test1]$ pwd
/home/zpeicn/test1
[zpeicn@x-study-as4 test1]$
3、使用touch命令在test1目录建立test1文件,并用ls命令察看
[zpeicn@x-study-as4 test1]$ touch test1
[zpeicn@x-study-as4 test1]$ ls
test1
[zpeicn@x-study-as4 test1]$
4、使用cp命令从/etc/拷贝profile文件到test1目录,拷贝test1文件到test2目录。并使用rm命令删除test1目录下的test1文件。
-rw-rw-r-- 1 zpeicn zpeicn 0 Jan 23 18:51 test1
[zpeicn@x-study-as4 test1]$ cp /etc/profile ./ [zpeicn@x-study-as4 test1]$ ll
Profile test1
[zpeicn@x-study-as4 test1]$ cp test1 ../test2
[zpeicn@x-study-as4 test1]$ rm test1
[zpeicn@x-study-as4 test1]$ ls
profile
[zpeicn@x-study-as4 test1]$
5、使用head命令和tail命令分别显示profil文件的前十行和后十行的内容
[zpeicn@x-study-as4 test1]$ head profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

pathmunge () {
if ! echo $PATH | /bin/egrep -q "(^|$1($|" ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
[zpeicn@x-study-as4 test1]$ tail profile
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC

for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
. $i
fi
done

unset i
unset pathmunge
[zpeicn@x-study-as4 test1]$
6、使用mv命令将profile文件移动到test3目录,并退回到家目录,使用rmdir命令删除test1,test4,test5目录。
[zpeicn@x-study-as4 test1]$ mv profile ../test3
[zpeicn@x-study-as4 test1]$ ls
[zpeicn@x-study-as4 test1]$ cd ..
[zpeicn@x-study-as4 ~]$ ls
Desktop test1 test2 test3 test4 test5
[zpeicn@x-study-as4 ~]$ rmdir test1 test4 test5
[zpeicn@x-study-as4 ~]$ ls
Desktop test2 test3
[zpeicn@x-study-as4 ~]$
7、使用rm命令删除test2目录,对比使用rmdir命令删除test3目录的情况
[zpeicn@x-study-as4 ~]$ rm -rf test2
[zpeicn@x-study-as4 ~]$ rmdir test3/ rmdir: `test3/': Directory not empty
[zpeicn@x-study-as4 ~]$

四、实验难点
在这个实验中没有特别的难点,但是要注意的是,rm命令删除目录的时候,不给任何提示,因此一定要谨慎,不然很容易删除不应该删除的文件。
五、实验回顾
Linux的图形环境中的文件浏览器可以完全替代这几个最基础,日常使用最多的命令。但是作为Linux用户仍然需要掌握这些命令,并逐步熟悉命令行的工作模式。随着学习的深入,将会面临越来越多的命令,因此尽快熟悉命令行会减少后面学习的压力。

TOP

第五章 Linux 下的文本编辑器vi

实验5、练习使用vi编辑器
一、实验目标:
熟悉vi编辑器的三种工作模式,使用vi编辑器编辑一个文本文件,并保存文件。
二、实验环境:
环境同上
三、实验步骤:
1、使用touch命令创建一个新的空文件:
[root@x-study -as4 ~]# touch newfile
3、使用vi编辑器打开这个文件:
[root@x-study -as4 ~]# vi newfile
3、在打开的文件中输入以下内容:
When we work—and also when we play—we use up energy. The energy may be physical or mental or a combination of the two. When our work or play is prolonged, we become tired and want to stop and rest or change to some other activity. If we do not stop, we become gradually less efficient.
4、练习在命令模式下复制、粘贴、删除等命令。
具体命令查看培训教材,这里不再赘述。
四、实验难点
理解vi编辑器的工作模式,掌握vi编辑器的命令模式下的编辑命令,掌握底行模式下的保存文件、退出vi、文本查找等命令。
五、实验回顾
在使用vi编辑器的时候,不要刻意地记忆命令模式和低行模式的命令,而不使用vi进行文件的编辑。记忆这些命令最好的办法是多使用,在需要特定的命令时,及时查看教材,或者上网查找vi使用手册。在使用过程中,常用的命令很快就可以熟练掌握。

TOP

本功能由奇虎搜索实现

相关主题

标题 作者 最后发表
第六章 压缩和备份 zpeicn 2008-09-20
第五章 Linux进程管理 zpeicn 2008-09-20
点击阅读更多关于的相关帖子  更多相关主题