`
xxtianxiaxing
  • 浏览: 654897 次
  • 性别: Icon_minigender_1
  • 来自: 陕西
社区版块
存档分类
最新评论

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

阅读更多
1.       添加用户u1u2,并设置口令(配置如下)
[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.       查看/etc/passwd/etc/shadow文件内容,确认两个用户建立
[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.       查看/home目录下是否有u1u2目录
 
[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.u1用户身份登录
[root@mxl ~]# su u1
[u1@mxl root]$
 
5.u1用户身份登录后,显示当前目录位置
[u1@mxl root]$ pwd
/root
6.u1目录下创建两个目录,分别为dir1dir2
[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.进入dir1目录用vi创建两个文件,文件名分别test1test2
[u1@mxl ~]$ cd dir1
 [u1@mxl dir1]$ vi test1
 
welcome to test1
WR 保存
[u1@mxl dir1]$ vi test2
 
welcome to test2
WR
8.使用多种方法查看文件内容
[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.进入dir2目录下用touch两个空文件test3test4
[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.dir1目录下的test1文件复制到/tmp下并查看是否有test1文件
[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.dir1目录下的test2移动到dir2目录下
[u1@mxl dir2]$ mv ../dir1/test2 ./
12.查看dir1目录下的文件
[u1@mxl dir2]$ ll ../dir1
total 4
-rw-rw-r-- 1 u1 u1 17 Jun 10 13:28 test1 目录dir1下已经没有test1文件了
 
13.查看dir2目录下的文件
[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
 
14.删除dir1目录及目录下的所有文件
[u1@mxl dir2]$ rm -rf ../dir1/test1
[u1@mxl dir2]$ ll ../dir1
total 0
 
15.删除dir2目录及目录下的所有文件
[u1@mxl ~]$ rm -rf dir2
[u1@mxl ~]$ ll
total 4
drwxrwxr-x 2 u1 u1 4096 Jun 10 13:49 dir1
16.root身份登录
[u1@mxl ~]$ su root
Password:
[root@mxl u1]#
17.ls -l命令显示/tmp/test1文件权限(并解释其含义)
[root@mxl /]# ll /tmp/test1
-rw-rw-r-- 1 u1 u1 17 Jun 10 13:37 /tmp/test1
属主有读\ 写的权限 属组有读\ 写权限 其他的用户只有读的权限
18./tmp/test1文件的属主改为u2,权限为读、写、可执行;属组改为u2,权限为只读;其它用户无任何权限
[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.以用户u2身份登录,查看/tmp/test1文件内容,内容是否可见?
[root@mxl /]# su u2
Password:123456 
[u2@mxl /]$ cat /tmp/test1
welcome to test1
20.以用户u1身份登录,查看/tmp/test1文件内容,内容是否可见?
[u2@mxl /]$ su u1
Password:
[u1@mxl /]$ cat /tmp/test1
cat: /tmp/test1: Permission denied  提示没有权限,呵呵,因为这个文件的属主与属组是u2所以当用此用户登陆有权限,u1没有权限在这个文件中u1就是其他的用户,而其他的用户我们没有给任何的权限,所以没有查看此文件的内容.
21.添加一个新用户u4u2组以用户u3的身份登录,查看/tmp/test1文件内容,内容是否可见?
[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.将已有用户u1添加到u2组以用户u1身份再次登录,查看/tmp/test1文件内容,内容是否可见?
 
[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命令
23.删除用户u1
[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.手工删除用户u4
[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.添加用户u5u6并设置口令(其中用户u5手工添加)
[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手工添加
[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.以用户u5身份登录,在/home/u5目录下用vi创建t1
[u5@mxl ~]$ vi t1
 
welcome to t1 这是输入的内容
27.root身份将用户u6加到组u5
[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.ll查看文件/home/u5/t1文件属性(属组权限是什么?)
[root@mxl /]# ll /home/u5/t1
-rw-rw-r-- 1 u5 u5 23 Jun 10 17:09 /home/u5/t1
属组对文件的权限是读\
 
29.ll查看目录/home/u5目录权限(该目录对于属组u5是否有权限)
[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.以用户u5身份登录,查看/home/u5/t1文件内容,内容是否可见?
[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.root身份登录为/home/u5/t1添加一个硬链接为/home/u6/t1
[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.ll命令分别查看/home/u5/t1/home/u6/t1文件属性(硬连接数、属主、属组等)两者是否相同
[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.在以用户u6身份登录,查看/home/u6/t1文件内容,内容是否可见?
[u6@mxl ~]$ cat  t1
welcome to t1
34.进入/media/cdrom目录(目录不存在的话需要创建),查看是否有文件
[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.将光驱/dev/cdrom挂接到目录/media/cdrom再次查看/media/cdrom目录是否有文件
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.卸载光驱
[root@mxl /]# eject
[root@mxl /]# ll /media/cdrom
total 0  卸载后在次查看光驱中已经没有任何文件了
1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics