您的位置:首页 > 运维架构 > Linux

初学linux做下这些题----多多练习

2008-06-19 20:56 267 查看
[align=center][/b] [/align]
1. [/b]添加用户u1[/b]和u2[/b],并设置口令([/b]配置如下)[/b]
[root@mxl /]# useradd u1
[root@mxl /]# useradd u2
[root@mxl /]# passwd u1
Changing password for user u1.
New UNIX password:
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@mxl /]# passwd u2
Changing password for user u2.
New UNIX password:
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
2. [/b]查看/etc/passwd[/b]及/etc/shadow[/b]文件内容,确认两个用户建立[/b]
[root@mxl /]# cat /etc/passwd
u1:x:502:502::/home/u1:/bin/bash
u2:x:503:503::/home/u2:/bin/bash
[root@mxl ~]# cat /etc/shadow
u1:$1$CwCsbz/P$/Nod9KfmG1YrJbjLjqWKU0:14040:0:99999:7:::
u2:$1$5A8z1F5L$gDvZJfpmUpc78YsUMUH4y.:14040:0:99999:7:::
3. [/b]查看/home[/b]目录下是否有u1[/b]和u2[/b]目录[/b]
[/b]
[root@mxl ~]# ll /home
total 4876
-rwxr--r-- 1 root root 4971243 Nov 16 2004 fssh54b56tbyba.exe
drwx------ 2 u1 u1 4096 Jun 10 12:52 u1
drwx------ 2 u2 u2 4096 Jun 10 12:53 u2
4.[/b]以u1[/b]用户身份登录[/b]
[root@mxl ~]# su u1
[u1@mxl root]$

5.[/b]以u1[/b]用户身份登录后,显示当前目录位置[/b]
[u1@mxl root]$ pwd
/root
6.[/b]在u1[/b]目录下创建两个目录,分别为dir1[/b]和dir2[/b]
[u1@mxl ~]$ mkdir dir1
[u1@mxl ~]$ mkdir dir2
[u1@mxl ~]$ ll
total 8
drwxrwxr-x 2 u1 u1 4096 Jun 10 13:20 dir1
drwxrwxr-x 2 u1 u1 4096 Jun 10 13:20 dir2
7.[/b]进入dir1[/b]目录用vi[/b]创建两个文件,文件名分别test1[/b]和test2[/b]
[u1@mxl ~]$ cd dir1
[u1@mxl dir1]$ vi test1

welcome to test1
WR 保存
[u1@mxl dir1]$ vi test2

welcome to test2
WR
8.[/b]使用多种方法查看文件内容[/b]
[u1@mxl dir1]$ ll
total 8
-rw-rw-r-- 1 u1 u1 17 Jun 10 13:28 test1
-rw-rw-r-- 1 u1 u1 17 Jun 10 13:30 test2
[u1@mxl dir1]$ cat test1
welcome to test1
[u1@mxl dir1]$ cat test2
welcome to test2
[u1@mxl dir1]$ more test2
welcome to test2
[u1@mxl dir1]$ more test1
welcome to test1
9.[/b]进入dir2[/b]目录下用touch[/b]两个空文件test3[/b]和test4[/b]
[u1@mxl ~]$ cd dir2
[u1@mxl dir2]$ touch test3
[u1@mxl dir2]$ touch test4
[u1@mxl dir2]$ ll
total 0
-rw-rw-r-- 1 u1 u1 0 Jun 10 13:36 test3
-rw-rw-r-- 1 u1 u1 0 Jun 10 13:36 test4

[u1@mxl dir2]$ touch test3 test4
[u1@mxl dir2]$ ll
total 0
-rw-rw-r-- 1 u1 u1 0 Jun 10 13:36 test3
-rw-rw-r-- 1 u1 u1 0 Jun 10 13:36 test4
10.[/b]将dir1[/b]目录下的test1[/b]文件复制到/tmp[/b]下并查看是否有test1[/b]文件[/b]
[u1@mxl dir2]$ cp ../dir1/test1 /tmp
[u1@mxl dir2]$ ll /tmp/test1
-rw-rw-r-- 1 u1 u1 17 Jun 10 13:37 /tmp/test1
11.[/b]将dir1[/b]目录下的test2[/b]移动到dir2[/b]目录下[/b]
[u1@mxl dir2]$ mv ../dir1/test2 ./
12.[/b]查看dir1[/b]目录下的文件[/b]
[u1@mxl dir2]$ ll ../dir1
total 4
-rw-rw-r-- 1 u1 u1 17 Jun 10 13:28 test1 目录dir1下已经没有test1文件了

13.[/b]查看dir2[/b]目录下的文件[/b]
[u1@mxl dir2]$ ll
total 4
-rw-rw-r-- 1 u1 u1 17 Jun 10 13:30 test2
-rw-rw-r-- 1 u1 u1 0 Jun 10 13:36 test3
-rw-rw-r-- 1 u1 u1 0 Jun 10 13:36 test4
[/b]
14.[/b]删除dir1[/b]目录及目录下的所有文件[/b]
[u1@mxl dir2]$ rm -rf ../dir1/test1
[u1@mxl dir2]$ ll ../dir1
total 0

15.[/b]删除dir2[/b]目录及目录下的所有文件[/b]
[u1@mxl ~]$ rm -rf dir2
[u1@mxl ~]$ ll
total 4
drwxrwxr-x 2 u1 u1 4096 Jun 10 13:49 dir1
16.[/b]以root[/b]身份登录[/b]
[u1@mxl ~]$ su root
Password:
[root@mxl u1]#
17.[/b]用ls -l[/b]命令显示/tmp/test1[/b]文件权限(并解释其含义)[/b]
[root@mxl /]# ll /tmp/test1
-rw-rw-r-- 1 u1 u1 17 Jun 10 13:37 /tmp/test1
属主有读\ 写的权限 属组有读\ 写权限 其他的用户只有读的权限
18.[/b]将/tmp/test1[/b]文件的属主改为u2[/b],权限为读、写、可执行;属组改为u2[/b],权限为只读;其它用户无任何权限[/b]
[root@mxl /]# chown u2.u2 ../tmp/test1
[root@mxl /]# ll ../tmp/test1
-rw-rw-r-- 1 u2 u2 17 Jun 10 13:37 ../tmp/test1
[root@mxl /]# chmod u+x,g-w,o-r ../tmp/test1 设置权限方法一
[root@mxl /]# ll ../tmp/test1
-rwxr----- 1 u2 u2 17 Jun 10 13:37 ../tmp/test1
[root@mxl /]# chmod u-x,g+w,o+r ../tmp/test1 取消设置的权限
[root@mxl /]# ll ../tmp/test1
-rw-rw-r-- 1 u2 u2 17 Jun 10 13:37 ../tmp/test1
[root@mxl /]# chmod 740 ../tmp/test1 设置权限方法二
[root@mxl /]# ll ../tmp/test1
-rwxr----- 1 u2 u2 17 Jun 10 13:37 ../tmp/test1
19.[/b]以用户u2[/b]身份登录,查看/tmp/test1[/b]文件内容,内容是否可见?[/b]
[root@mxl /]# su u2
Password:123456
[u2@mxl /]$ cat /tmp/test1
welcome to test1
20.[/b]以用户u1[/b]身份登录,查看/tmp/test1[/b]文件内容,内容是否可见?[/b]
[u2@mxl /]$ su u1
Password:
[u1@mxl /]$ cat /tmp/test1
cat: /tmp/test1: Permission denied →提示没有权限,呵呵,因为这个文件的属主与属组是u2所以当用此用户登陆有权限,以u1没有权限在这个文件中u1就是其他的用户,而其他的用户我们没有给任何的权限,所以没有查看此文件的内容.
21.[/b]添加一个新用户u4[/b]到u2[/b]组以用户u3[/b]的身份登录,查看/tmp/test1[/b]文件内容,内容是否可见?[/b]
[root@mxl ~]# useradd -g u2 u4
[root@mxl ~]# cat /etc/passwd
u1:x:502:502::/home/u1:/bin/bash
u2:x:503:503::/home/u2:/bin/bash
u4:x:505:503::/home/u4:/bin/bash
[root@mxl etc]# su u4
[u4@mxl etc]$ cat /tmp/test1
welcome to test1
22.[/b]将已有用户u1[/b]添加到u2[/b]组以用户u1[/b]身份再次登录,查看/tmp/test1[/b]文件内容,内容是否可见?[/b]
[/b]
[root@mxl home]# chgrp u2 u1
[root@mxl home]# ll
total 4880
-rwxr--r-- 1 root root 4971243 Nov 16 2004 fssh54b56tbyba.exe
drwx------ 3 u1 u2 4096 Jun 10 14:42 u1
drwx------ 2 u2 u2 4096 Jun 10 14:42 u2
drwx------ 2 u4 u2 4096 Jun 10 14:43 u4
[root@mxl home]# vi ../etc/passwd
u1:x:502:502::/home/u1:/bin/bash→改成u1:x:502:503::/home/u1:/bin/bash
u2:x:503:503::/home/u2:/bin/bash
u4:x:505:503::/home/u4:/bin/bash
[root@mxl home]# su u1
[u1@mxl home]$ cat ../tmp/test1
welcome to test1
最好的方法就是使用gpasswd[/b]命令[/b]
23.[/b]删除用户u1[/b]
[root@mxl /]# userdel -r u1
[root@mxl home]# ll 查看可以看到u1已经被删除
total 4876
-rwxr--r-- 1 root root 4971243 Nov 16 2004 fssh54b56tbyba.exe
drwx------ 2 u2 u2 4096 Jun 10 14:42 u2 drwx------ 2 u4 u2 4096 Jun 10 14:43 u4

24.[/b]手工删除用户u4[/b]
[root@mxl home]# rm -rf u4
[root@mxl home]# ll
total 4872
-rwxr--r-- 1 root root 4971243 Nov 16 2004 fssh54b56tbyba.exe
drwx------ 2 u2 u2 4096 Jun 10 14:42 u2
[root@mxl home]# vi ../etc/passwd
u2:x:503:503::/home/u2:/bin/bash
u4:x:505:503::/home/u4:/bin/bash 在VI编辑器中把这行删除然后保存
删除一行的命令是cc
[root@mxl /]# vi /etc/shadow
U4:!!:14040:0:99999:7::: 同上在VI编辑器里把这行删除然后保存
删除一行的命令是cc
25.[/b]添加用户u5[/b]、u6[/b]并设置口令(其中用户u5[/b]手工添加)[/b]
[root@mxl /]# useradd u6
[root@mxl /]# passwd u6
Changing password for user u6.
New UNIX password:
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
u5[/b]手工添加[/b]
[root@mxl /]# vi /etc/passwd
u5:x:502:502::/home/u5:/bin/bash新加入的此行
[root@mxl /]# vi /etc/shadow
u5:!!:14040:0:99999:7::: 新加入此行
[root@mxl /]# vi /etc/group
u5:x:502:新加入此行
[root@mxl /]# mkdir /home/u5
[root@mxl /]# cp /etc/skel/.* /home/u5
cp: omitting directory `/etc/skel/.'
cp: omitting directory `/etc/skel/..'
[root@mxl home]# ll
total 4880
-rwxr--r-- 1 root root 4971243 Nov 16 2004 fssh54b56tbyba.exe
drwx------ 2 u2 u2 4096 Jun 10 14:42 u2
drwx------ 2 u5 u5 4096 Jun 10 16:56 u5
drwx------ 2 u6 u6 4096 Jun 10 15:20 u6
[root@mxl /]# passwd u5
Changing password for user u5.
New UNIX password:
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@mxl /]# su u5
[u5@mxl /]$ su u5
Password:
26.[/b]以用户u5[/b]身份登录,在/home/u5[/b]目录下用vi[/b]创建t1[/b]
[u5@mxl ~]$ vi t1

welcome to t1 这是输入的内容
27.[/b]以root[/b]身份将用户u6[/b]加到组u5[/b]
[root@mxl /]# gpasswd -help
gpasswd: invalid option -- h
Usage: gpasswd [-r|-R] group
gpasswd [-a user] group
gpasswd [-d user] group
gpasswd [-A user,...] [-M user,...] group
以上是把用户加入组的命令的一些帮助信息

[root@mxl /]# gpasswd -a u6 u5
Adding user u6 to group u5
28.[/b]用ll[/b]查看文件/home/u5/t1[/b]文件属性(属组权限是什么?)[/b]
[root@mxl /]# ll /home/u5/t1
-rw-rw-r-- 1 u5 u5 23 Jun 10 17:09 /home/u5/t1
属组对文件的权限是读\ 写

29.[/b]用ll[/b]查看目录/home/u5[/b]目录权限(该目录对于属组u5[/b]是否有权限)[/b]
[root@mxl /]# ll /home
total 4876
-rwxr--r-- 1 root root 4971243 Nov 16 2004 fssh54b56tbyba.exe
drwx------ 2 u5 u5 4096 Jun 10 17:09 u5
drwx------ 2 u6 u6 4096 Jun 10 15:20 u6
属组对目录没有任何权限

30.[/b]以用户u5[/b]身份登录,查看/home/u5/t1[/b]文件内容,内容是否可见?[/b]
[u5@mxl home]$ cd u5
[u5@mxl ~]$ ll
total 4
-rw-rw-r-- 1 u5 u5 23 Jun 10 17:09 t1
[u5@mxl ~]$ cat t1
welcome to t1
31.[/b]以root[/b]身份登录为/home/u5/t1[/b]添加一个硬链接为/home/u6/t1[/b]
[root@mxl /]# ln /home/u5/t1 /home/u6/t1
[root@mxl /]#
[root@mxl /]# ll /home/u6
total 4
-rw-rw-r-- 2 u5 u5 23 Jun 10 17:09 t1

32.[/b]用ll[/b]命令分别查看/home/u5/t1[/b]和/home/u6/t1[/b]文件属性(硬连接数、属主、属组等)两者是否相同[/b]
[root@mxl /]# ll /home/u5
total 4
-rw-rw-r-- 2 u5 u5 23 Jun 10 17:09 t1
[root@mxl /]# ll /home/u6
total 4
-rw-rw-r-- 2 u5 u5 23 Jun 10 17:09 t1
属主与属组都是u5
33.[/b]在以用户u6[/b]身份登录,查看/home/u6/t1[/b]文件内容,内容是否可见?[/b]
[u6@mxl ~]$ cat t1
welcome to t1
34.[/b]进入/media/cdrom[/b]目录(目录不存在的话需要创建),查看是否有文件[/b]
[root@mxl media]# cd cdrom
bash: cd: cdrom: No such file or directory
[root@mxl media]# mkdir cdrom
[root@mxl media]# ll
total 4
drwxr-xr-x 2 root root 4096 Jun 10 17:40 cdrom

35.[/b]将光驱/dev/cdrom[/b]挂接到目录/media/cdrom[/b]再次查看/media/cdrom[/b]目录是否有文件[/b]
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@mxl /]# ll /media/cdrom
total 240
drwxr-xr-x 2 root root 2048 Feb 9 2007 Cluster
drwxr-xr-x 2 root root 2048 Feb 9 2007 ClusterStorage
-rw-r--r-- 7 root root 8446 Jan 25 2007 EULA
-rw-r--r-- 7 root root 18416 Dec 1 2006 GPL
-rw-r--r-- 7 root root 8223 Feb 8 2007 README-en
-rw-r--r-- 7 root root 74003 Feb 8 2007 RELEASE-NOTES-en
-rw-r--r-- 7 root root 1175 Feb 9 2007 RPM-GPG-KEY-redhat-auxiliary
-rw-r--r-- 7 root root 1706 Feb 9 2007 RPM-GPG-KEY-redhat-beta
-rw-r--r-- 7 root root 1990 Feb 9 2007 RPM-GPG-KEY-redhat-former
-rw-r--r-- 7 root root 1164 Feb 9 2007 RPM-GPG-KEY-redhat-release
drwxr-xr-x 2 root root 118784 Feb 9 2007 Server
-r--r--r-- 1 root root 2928 Feb 9 2007 TRANS.TBL
drwxr-xr-x 2 root root 2048 Feb 9 2007 VT
36.[/b]卸载光驱[/b]
[root@mxl /]# eject[/b]
[root@mxl /]# ll /media/cdrom[/b]
total 0 [/b]卸载后在次查看光驱中已经没有任何文件了[/b]本文出自 “点滴记录-系统运维-孟星伦” 博客,请务必保留此出处http://haoyou168.blog.51cto.com/284295/83022
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: