Linux指令系统

Linux指令系统

(一)目录操作

【需求】

  1. 查看/tmp目录下的内容;
  2. 如果/tmp目录下没有子目录myshare,就建立该目录;
  3. 要求目录myshare的拥有者为bin,工作组为bin;
  4. 要求myshare下的所有文件和子目录都自动拥有工作组为bin。

【系统及软件环境】

操作系统:Red Hat AS 4.0

【实验配置文件及命令】

1.配置文件:无

2.命令:/bin/ls,/bin/mkdir,/bin/chown,/bin/chmod,/bin/chgrp 

【实验步骤】

1.当前的分区表信息。

[root@linux /]# cd  /tmp

[root@linux tmp]# ls

ksocket-root  linux-2.6.11.1  orbit-root  proftpd-1.2.9  proftpd-1.2.9.tar.gz

 

2.目录myshare。

[root@linux tmp]# mkdir   myshare

[root@linux tmp]# ls  -ld  myshare/

drwxr-xr-x       2  root     root         4096 May 27 14:01 myshare/

 

3.修改目录的拥有者和工作组。

[root@linux tmp]# chown  bin  myshare/

[root@linux tmp]# ls -ld  myshare/

drwxr-xr-x    2  bin      root         4096 May 27 14:01  myshare/

[root@linux tmp]# chgrp  bin   myshare/

[root@linux tmp]# ls -ld  myshare/

drwxr-xr-x    2  bin      bin         4096 May 27 14:01  myshare/

 

4.使myshare下的所有文件和子目录都自动拥有工作组为bin。

[root@linux tmp]# chmod  g+s   myshare

[root@linux tmp]# ls  -ld   myshare/

drwxr-sr-x    2 bin      bin          4096 May 27 14:01 myshare/

 

5.测试。

[root@linux tmp]# mkdir   myshare/testdir

[root@linux tmp]# ls  -l  myshare/

total 4

drwxr-sr-x    2 root     bin          4096 May 27 14:15 testdir

【实验故障与分析】

下面的表格中列出了在实验过程中可能会出现的故障及其解决方法。看看是不是对你的实验有所帮助?如果你在实验中还遇到了其他的问题或故障,不妨记录在表格中,通过自己的实践,或者与老师、同学一起找找解决问题的方法。

序  号

实验故障

分析与解决

1

在你的系统上ls显示tmp目录的内容与本书上面列出的内容不一致

这是正常的,因为每个系统中tmp目录的内容都可能不一样

2

 

 

3

 

 

【启发联想】

1.如何一次性创建1个子目录树?

2.绝对路径与相对路径的区别是怎样的?何时使用相对路径比较方便?

文件操作

【需求】

  1. 查看/tmp目录下的内容及属性;
  2. 如果/tmp目录下没有文件testfile,就新建该文件。

(1)要求该文件的权限模式为拥有者可读、写和执行,其他人只能读和执行;

(2)把该文件备份到/tmp/myshare目录下,并改名为testfile.bak;

(3)在/root目录下为该文件创建一个符号连接。

【系统及软件环境】

操作系统:Red Hat AS 4.0

【实验配置文件及命令】

1.配置文件:无

2.命令:/bin/ls,/bin/cp,/bin/touch,/bin/chmod,/bin/ln

【实验步骤】

1.查看/tmp目录下的内容及属性。

[root@linux /]# cd  /tmp

[root@linux tmp]# ls  -F

ksocket-root/    myshare/     proftpd-1.2.9/

linux-2.6.11.1/  orbit-root/  proftpd-1.2.9.tar.gz

 

2.新建testfile文件。

[root@linux tmp]# touch  testfile

[root@linux tmp]# ls  -l

total 1000

drwx------    2 root     root          4096 Mar 27 16:26 ksocket-root

drwxrwxr-x   18 test     users        4096 May 23 19:30 linux-2.6.11.1

drwxr-sr-x    3 bin      bin          4096 May 27 14:19 myshare

drwx------    2 root     root          4096 May  2 00:32 orbit-root

drwxr-xr-x   10 gdlc     gdlc         4096 May 17 03:54 proftpd-1.2.9

-rw-r--r--    1 root     root         995350 May 13 09:14 proftpd-1.2.9.tar.gz

-rw-r--r--    1 root     root              0 May 27 14:26 testfile

 

3.设置该文件的权限模式。

[root@linux tmp]# chmod  755   testfile

[root@linux tmp]# ls  -l  testfile

-rwxr-xr-x    1 root     root            0 May 27 14:26 testfile

 

4.把该文件备份到/tmp/myshare目录下,并改名为testfile.bak。

[root@linux tmp]# cp  testfile   myshare/testfile.bak

[root@linux tmp]#  ls  -l  myshare/

total 4

drwxr-sr-x    2 root     bin          4096 May 27 14:15 testdir

-rwxr-xr-x    1 root     bin             0 May 27 14:30 testfile.bak

 

5.在/root目录下为该文件创建1个符号连接。

[root@linux tmp]# ln  -s  /tmp/testfile    /root/testfile.ln

[root@linux tmp]# ls  -l  /root/testfile.ln

lrwxrwxrwx    1  root     root      13 May 27 14:32  /root/testfile.ln -> /tmp/testfile

【实验故障与分析】

下面的表格中列出了在实验过程中可能会出现的故障及其解决方法。看看是不是对你的实验有所帮助?如果你在实验中还遇到了其他的问题或故障,不妨记录在表格中,通过自己的实践,或者与老师、同学一起找找解决问题的方法。

序 号

实验故障

分析与解决

1

拷贝testfile到myshare目录下时报错

可能是由于系统中没有myshare这个目录,用户需要先创建这个目录

2

 

 

3

 

 

【启发联想】

1.mv 与cp有何区别?

2.如何给目录创建符号链接?可以为目录创建硬链接吗?

(三)查找过滤操作

【需求】

  1. 查找cat和find命令程序的路径;
  2. 查找系统中是否存在文件grub.conf;
  3. 查找系统中所有的空文件,并记录到/tmp/zerofile.log;
  4. 搜索inittab文件中含有initdefault字符串的行;
  5. 过滤显示/etc下文件名中包含init字符串的文件或目录全名。

【系统及软件环境】

操作系统:Red Hat AS 4.0

【实验配置文件及命令】

1.配置文件:无

2.命令:/usr/bin/which,/usr/bin/find,/bin/grep,/bin/cat,/bin/ls

【实验步骤】

1.查找cat和find命令程序的路径。

[root@linux /]# which  cat   find

/bin/cat

/usr/bin/find

2.查找系统中是否存在文件grub.conf。

[root@linux tmp]# find  /  -name  grub.conf

/boot/grub/grub.conf

/home/bobs/grub.conf

/etc/grub.conf

 

3.查找系统中所有的空文件,并记录到/tmp/zerofile.log。

[root@linux tmp]# find  /   -size  0  > /tmp/zerofile.log

 

4.搜索inittab文件中含有initdefault字符串的行。

[root@linux tmp]# cat  /etc/inittab  | grep  initdefault

#   0 - halt (Do NOT set initdefault to this)

#   6 - reboot (Do NOT set initdefault to this)

id:3:initdefault:

 

5.过滤显示/etc下文件名中包含init字符串的文件或目录全名。

[root@linux tmp]# ls  /etc/   |  grep  init

init.d

initlog.conf

inittab

rc.sysinit

【实验故障与分析】

下面的表格中列出了在实验过程中可能会出现的故障及其解决方法。看看是不是对你的实验有所帮助?如果你在实验中还遇到了其他的问题或故障,不妨记录在表格中,通过自己的实践,或者与老师、同学一起找找解决问题的方法。

序号

实验故障

分析与解决

1

执行某个命令时报错

可能是由于漏掉了某个“/”符号或空白符号

2

 

 

3

 

 

【启发联想】

1.find 与locate有何区别?

2.管道的工作原理是怎样的?

(四)压缩打包操作

【需求】

  1. 把/tmp目录打包成tmp.tar,放到/root目录下;
  2. 把/tmp目录压缩打包成tmp.tar.gz,放到/root目录下;
  3. 比较tmp.tar和tmp.tar.gz的大小;
  4. 不解包只查看压缩包tmp.tar.gz中的内容;
  5. 解压tmp.tar.gz中的内容到/tmp/myshare目录。

【系统及软件环境】

操作系统:Red Hat AS 4.0

【实验配置文件及命令】

1.配置文件:无

2.命令:/bin/tar,/bin/ls

【实验步骤】

1.把/tmp目录打包成tmp.tar,放到/root目录下。

[root@linux tmp]# tar  cf   /root/tmp.tar   /tmp/*

 

2.把/tmp目录压缩打包成tmp.tar.gz,放到/root目录下。

[root@linux tmp]# tar  zcvf   /root/tmp.tar.gz   /tmp/*

 

3.比较tmp.tar和tmp.tar.gz的大小。

[root@linux tmp]# ls  -l   /root/tmp.tar   /root/tmp.tar.gz

-rw-r--r--    1 root     root     215203840  May 27 15:25 /root/tmp.tar

-rw-r--r--    1 root     root      49351161  May 27 15:26 /root/tmp.tar.gz

 

4.不解包只查看压缩包tmp.tar.gz中的内容。

[root@linux tmp]# tar  ztf   /root/tmp.tar.gz

tmp/linux-2.6.11.1/drivers/video/sa1100fb.c

tmp/linux-2.6.11.1/drivers/video/maxinefb.c

tmp/linux-2.6.11.1/drivers/video/vga16fb.c

tmp/linux-2.6.11.1/drivers/video/retz3fb.h

tmp/linux-2.6.11.1/drivers/video/tdfxfb.c

tmp/linux-2.6.11.1/drivers/video/q40fb.c

tmp/linux-2.6.11.1/drivers/video/virgefb.c

5.解压tmp.tar.gz的内容到/tmp/myshare目录。

[root@linux tmp]# tar  zxvf   /root/tmp.tar.gz   -C    /tmp/myshare/ 

【实验故障与分析】

下面的表格中列出了在实验过程中可能会出现的故障及其解决方法。看看是不是对你的实验有所帮助?如果你在实验中还遇到了其他的问题或故障,不妨记录在表格中,通过自己的实践,或者与老师、同学一起找找解决问题的方法。

序  号

实验故障

分析与解决

1

在解压某个包时报错

这可能是由于你误用了某个参数选项

2

 

 

3

 

 

【启发联想】

1.可以把打包和压缩分开来做吗,即先打包再压缩?

2.比较一下采用不同压缩格式进行压缩的效果?

(五)进程操作

【需求】

  1. 查看系统中消耗CPU资源最多的几个进程;
  2. 查看系统所有进程;
  3. 查找ssh服务守护进程的进程ID号;
  4. 假设ssh服务守护进程出现了问题,杀掉该进程。

【系统及软件环境】

操作系统:Red Hat AS 4.0

【实验配置文件及命令】

1.配置文件:无

2.命令:/usr/bin/top,/bin/ps,/bin/kill

【实验步骤】

1.查看系统中消耗CPU资源最多的几个进程。

[root@linux tmp]# top

15:36:23  up  1:39,  3 users,  load average: 0.00, 0.07, 0.08

42 processes: 41 sleeping, 1 running, 0 zombie, 0 stopped

CPU states:  cpu    user    nice  system    irq  softirq  iowait    idle

           total    0.0%   0.0%  0.0%    0.0%  1.9%   0.0%   98.0%

Mem:   303420k av,  299476k used,    3944k free,       0k shrd,   61904k buff

                    123880k actv,   55892k in_d,    6236k in_c

Swap:  385552k av,       0k used,  385552k free                120580k cached

 

PID USER PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM TIME CPU COMMAND

    1 root      15   0   504  504     452 S    0.0  0.1   0:04   0 init

    2 root      15   0     0    0     0 SW    0.0  0.0   0:00   0 keventd

    3 root      15   0     0    0     0 SW    0.0  0.0   0:00   0 kapmd

    4 root      34  19     0    0     0 SWN   0.0  0.0   0:00   0 ksoftirqd/0

    7 root      25   0     0    0     0 SW    0.0  0.0   0:00   0 bdflush

    5 root      15   0     0    0     0 SW    0.0  0.0   0:00   0 kswapd

    6 root      15   0     0    0     0 SW    0.0  0.0   0:00   0 kscand

    8 root      15   0     0    0     0 SW    0.0  0.0   0:00   0 kupdated

 

2.查看系统所有进程。

[root@linux tmp]# ps  -ef

UID        PID  PPID  C STIME TTY          TIME CMD

root         1     0  0 13:56 ?        00:00:04 init

root         2     1  0 13:56 ?        00:00:00 [keventd]

root         3     1  0 13:56 ?        00:00:00 [kapmd]

root         4     1  0 13:56 ?        00:00:00 [ksoftirqd/0]

root         7     1  0 13:56 ?        00:00:00 [bdflush]

root         5     1  0 13:56 ?        00:00:00 [kswapd]

root         6     1  0 13:56 ?        00:00:00 [kscand]

root         8     1  0 13:56 ?        00:00:00 [kupdated]

 

3.查找ssh服务守护进程的进程ID号。

[root@linux tmp]# ps  -ef  |grep  sshd

root      2324     1  0 13:57 ?        00:00:00 /usr/sbin/sshd

root      2480  2324  0 14:00 ?        00:00:01 sshd: root@pts/0

root      2683  2324  0 15:22 ?        00:00:00 sshd: root@pts/1

root      2777  2685  0 15:49 pts/1    00:00:00 grep sshd

结果显示:ssh服务守护进程的进程ID号为2324。

 

4.假设ssh服务守护进程出现了问题,则杀掉该进程。

[root@linux tmp]# kill  2324

【实验故障与分析】

下面的表格中列出了在实验过程中可能会出现的故障及其解决方法。看看是不是对你的实验有所帮助?如果你在实验中还遇到了其他的问题或故障,不妨记录在表格中,通过自己的实践,或者与老师、同学一起找找解决问题的方法。

序 号

实验故障

分析与解决

1

执行kill命令后,被杀的进程仍然存在

这说明该进程没有被杀掉,需要加-9选项来发送强制信号

2

 

 

3

 

 

【启发联想】

1.top命令有何危害?

2.如何快速查找到某个你希望了解的进程信息?

 

 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值