令
一、
实验目标:
练习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用户仍然需要掌握这些命令,并逐步熟悉命令行的工作模式。随着学习的深入,将会面临越来越多的命令,因此尽快熟悉命令行会减少后面学习的压力。