实验二 Linux 命令系统

更新时间:2023-10-26 00:00:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

Linux系统管理员实训手册

实验二 Linux指令系统

(一)目录操作

【需求】

? ? ? ?

查看/tmp目录下的内容;

如果/tmp目录下没有子目录myshare,就建立该目录; 要求目录myshare的拥有者为bin,工作组为bin;

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

【系统及软件环境】

操作系统:Quick linux

【实验配置文件及命令】

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/

26

实验二 Linux命令系统

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 2 3 实验故障 分析与解决 在你的系统上ls显示tmp目录的内容与这是正常的,因为每个系统中本书上面列出的内容不一致 tmp目录的内容都可能不一样 (二)文件操作

【需求】

? 查看/tmp目录下的内容及属性;

? 如果/tmp目录下没有文件testfile,就新建该文件。

(1)要求该文件的权限模式为拥有者可读、写和执行,其他人只能读和执行; (2)把该文件备份到/tmp/myshare目录下,并改名为testfile.bak; (3)在/root目录下为该文件创建一个符号连接。

【系统及软件环境】

操作系统:Quick linux

【实验配置文件及命令】

1.配置文件:无

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

27

Linux系统管理员实训手册

【实验步骤】

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

28

实验二 Linux命令系统

【实验故障与分析】

下面的表格中列出了在实验过程中可能会出现的故障及其解决方法。 序 号 1 2 3 实验故障 拷贝testfile到myshare目录下时报错 分析与解决 可能是由于系统中没有myshare这个目录,用户需要先创建这个目录 (三)查找过滤操作

【需求】

? ? ? ? ?

查找cat和find命令程序的路径; 查找系统中是否存在文件grub.conf;

查找系统中所有的空文件,并记录到/tmp/zerofile.log; 搜索inittab文件中含有initdefault字符串的行;

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

【系统及软件环境】

操作系统:Quick linux

【实验配置文件及命令】

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。

29

Linux系统管理员实训手册

[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 实验故障 执行某个命令时报错 分析与解决 可能是由于漏掉了某个“/”符号或空白符号 (四)压缩打包操作

【需求】

? ? ? ? ?

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

把/tmp目录压缩打包成tmp.tar.gz,放到/root目录下; 比较tmp.tar和tmp.tar.gz的大小;

不解包只查看压缩包tmp.tar.gz中的内容; 解压tmp.tar.gz中的内容到/tmp/myshare目录。

【系统及软件环境】

操作系统:Quick linux

【实验配置文件及命令】

1.配置文件:无

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

30

本文来源:https://www.bwwdw.com/article/0302.html

Top