Linux必会面试题--1

1.列出你所知道的所有vi,vim编辑器的编辑模式,普通模式,命令模式。这三种模式下的操作指令

编辑模式:无
普通模式:G  gg yy p d  dd  D u  r  x   $  ^  dG  i  a   o  A  I  O
命令模式: :  /   :wq   :x   shift+zz   :set nu  :set ic  :set list

2.在当前系统能ping通百度的情况下,使用命令(curl cip.cc)查看(公网IP)当前网络出口地址,取出关键字"数据二"所在的行,以空格为分隔符,取出第三列的内容

[root@chengyinwu ~]# curl cip.cc |grep '数据二' |awk '{print $3}'

3.linux系统存放所有用户密码信息的文件是?

/etc/shadow
/etc/passwd

5.存放用户账户信息的配置文件是?

/etc/default/useradd
/etc/login.defs

6.改变文件所有者的命令为 (B)
A.chmod
B.chown
C.cat
D.vim

7.假设公司研发部的用户David和Peter属于组A,财务部的用户life和laowang属于组B
(1)建立相应的用户和组,并设置相应的对应关系

[root@yinwucheng ~]# groupadd A
[root@yinwucheng ~]# useradd David -g A
[root@yinwucheng ~]# useradd Peter -g A
[root@yinwucheng ~]# id David
uid=1124(David) gid=1126(A) groups=1126(A)

[root@yinwucheng ~]# groupadd B
[root@yinwucheng ~]# useradd life -g B
[root@yinwucheng ~]# useradd laowang -g B
[root@yinwucheng ~]# id life
uid=1126(life) gid=1127(B) groups=1127(B)

(2)建立目录office_a,该目录里面的文件只能由研发部人员读取、增加、删除、修改以及执行,其他用户不能对该目录进行任何操作

[root@yinwucheng ~]# mkdir office_a  //建目录
[root@yinwucheng ~]# ll -d office_a/   //查看默认权限
drwxr-xr-x. 2 root root 6 Aug  9 16:03 office_a/
[root@yinwucheng ~]# chmod 750 office_a/
[root@yinwucheng ~]# ll -d office_a/
drwxr-x---. 2 root root 6 Aug  9 16:03 office_a/

(3)建立目录office_b,该目录里面的文件只能由财务部人员读取、增加、删除、修改以及执行,其他用户不能对该目录进行任何操作

[root@yinwucheng /tmp]# mkdir office_b
[root@yinwucheng /tmp]# ll -d office_b
drwxr-xr-x. 2 root root 6 Aug 10 14:44 office_b
[root@yinwucheng /tmp]# chown .B office_b
[root@yinwucheng /tmp]# chmod 770 office_b

(4)建立目录office_c,该目录里面的文件研发部人员可以读取、增加、删除、修改以及执行,其他部门只能做查看操作

[root@yinwucheng /tmp]# mkdir office_c
[root@yinwucheng /tmp]# ll -d office_c
drwxr-xr-x. 2 root root 6 Aug 10 14:46 office_c
[root@yinwucheng /tmp]# chown .A office_c
[root@yinwucheng /tmp]# chmod 774 office_c

(5)建立目录office_d,该目录里面的文件只有研发部的经理David拥有所有操作权限,研发部的其他人只有查看权限,其他部门不能进行任何操作

[root@yinwucheng /tmp]# mkdir office_d
[root@yinwucheng /tmp]# ll -d office_d
drwxr-xr-x. 2 root root 6 Aug 10 14:49 office_d
[root@yinwucheng /tmp]# chown David.A office_d
[root@yinwucheng /tmp]# chmod 740 office_d
[root@yinwucheng /tmp]# ll -d office_d
drwxr-----. 2 David A 6 Aug 10 14:49 office_d

8.新建目录/web1,/web2,/web3

[root@yinwucheng ~]# mkdir /web{1..3}

(1)更改/web1目录的权限,使其他用户对它没有任何权限;

[root@yinwucheng ~]# ll -d /web1
drwxr-xr-x. 2 root root 6 Aug  9 17:22 /web1
[root@yinwucheng ~]# chmod 750 /web1
[root@yinwucheng ~]# ll -d /web1
drwxr-x---. 2 root root 6 Aug  9 17:22 /web1

(2)更改/web2目录的权限,使所属组对它拥有读写执行权限;

[root@yinwucheng ~]# ll -d /web2
drwxr-xr-x. 2 root root 6 Aug  9 17:22 /web2
[root@yinwucheng ~]# chmod 775 /web2
[root@yinwucheng ~]# ll -d /web2
drwxrwxr-x. 2 root root 6 Aug  9 17:22 /web2

(3)更改/web3目录的权限,任何用户都可以读写,但是在/web3目录中创建的任何文件都属于grp1组

[root@yinwucheng /tmp]# groupadd grp1
[root@yinwucheng /tmp]# chgrp grp1 /web3
[root@yinwucheng /tmp]# chmod 777 /web3
[root@yinwucheng /tmp]# ll -d /web3
drwxrwxrwx. 2 root grp1 6 Aug 10 15:22 /web3
[root@yinwucheng /tmp]# chmod g+s /web3
[root@yinwucheng /tmp]# ll -d /web3
drwxrwsrwx. 2 root grp1 6 Aug 10 15:22 /web3

9.新建用户zhangsan,lisi,wangergou,三个用户都属于同一个用户组f4,密码都为oldboy

[root@yinwucheng ~]# groupadd f4
[root@yinwucheng ~]# useradd zhangsan -g f4
[root@yinwucheng ~]# useradd lisi -g f4
[root@yinwucheng ~]# useradd wangergou -g f4
[root@yinwucheng ~]# echo "oldboy" |passwd --stdin zhangsan 
Changing password for user zhangsan.
passwd: all authentication tokens updated successfully.
[root@yinwucheng ~]# echo "oldboy" |passwd --stdin lisi
Changing password for user lisi.
passwd: all authentication tokens updated successfully.
[root@yinwucheng ~]# echo "oldboy" |passwd --stdin wangergou
Changing password for user wangergou.
passwd: all authentication tokens updated successfully.

(1)上述用户和组都能在/data/code目录,访问,创建,删除文件,其他用户无法访问该目录

[root@yinwucheng /tmp]# mkdir -p /data/code
[root@yinwucheng /tmp]# chown .f4 /data/code/
[root@yinwucheng /tmp]# ll -d /data/code/
drwxr-xr-x. 2 root f4 6 Aug 10 15:38 /data/code/
[root@yinwucheng /tmp]# chmod 770 /data/code/

(2)code目录下创建的所有文件自动归属于f4组所有

[root@yinwucheng /tmp]# chmod g+s /data/code/

(3)现在新增了一批用户,属于默认组,需要开放其他用户在code目录的读权限

[root@yinwucheng /tmp]# chmod 774 /data/code/

(4)新增的所有其他用户在code目录下创建的文件自动归属f4组

[root@yinwucheng /tmp]# chmod 777 /data/code/

10.有两个用户组,分别为python组、Linux组,python组的人可以修改读取python组的文件,但不能让Linux组的人读取;Linux组的人可以修改读取Linux组的文件,但不能让python组的人读取。

[root@yinwucheng ~]# groupadd python
[root@yinwucheng ~]# groupadd linux
[root@yinwucheng ~]# mkdir /python
[root@yinwucheng ~]# chown .python /python/
[root@yinwucheng ~]# chmod 770 /python/

[root@yinwucheng ~]# mkdir /linux
[root@yinwucheng ~]# chown .linux /linux
[root@yinwucheng ~]# chmod 770 /linux/

11.输入df -h,取出当前系统根分区剩余可用磁盘空间

[root@chengyinwu ~]# df -h |awk 'NR==2 {print $4}'
36G

12.显示/proc/meminfo文件中以s开头的行(忽略大小写)

[root@yinwucheng ~]# grep -i '^s' /proc/meminfo

13.在当前目录中新建文件text,假设该文件的权限为614。现要求设置该文件属主(u)增加执行权限,属组(g)增加写权限,其他用户(o)删除读权限,应该如何操作,另外修改后的权限用字母应该如何表示

[root@yinwucheng ~]# touch text
[root@yinwucheng ~]# chmod 614 text
[root@yinwucheng ~]# chmod u+x text 
[root@yinwucheng ~]# chmod g+w text 
[root@yinwucheng ~]# chmod o-r text
[root@yinwucheng ~]# ll
-rwx-wx---. 1 root root    0 Aug 10 16:19 text

14.在当前目录中创建目录aaa,并把该目录的权限设置为只有文件主有读、写和执行权限

[root@yinwucheng ~]# mkdir aaa
[root@yinwucheng ~]# chmod 700 aaa/

15.设某文件myfile的权限为-rw-r--r--,若要增加所有人可执行的权限,应该怎么做

[root@yinwucheng ~]# touch myfile
[root@yinwucheng ~]# chmod 644 myfile
[root@yinwucheng ~]# chmod o+x myfile

16.输入时间命令"date"将当前系统时间输出到/data/1.txt

[root@yinwucheng ~]# date > /data/1.txt

17.输入时间命令"date"将当前系统时间追加到/data/1.txt

[root@yinwucheng ~]# date >> /data/1.txt

18.在当前系统能ping通百度的情况下,使用" ping -c3 baidu.com "将返回的信息输出到/data/1.txt

[root@chengyinwu ~]# ping -c3 baidu.com > /data/1.txt

19.接上题,将/data/1.txt中,出现关键字time的第一行取出,然后将该行中所消耗的延时信息取出(time等于的数值就是消耗的延时信息)

[root@chengyinwu ~]# grep 'time' /data/1.txt |awk 'NR==1 {print $8}' |awk -F "=" '{print $2}'
27.5

20.使用“ls /ta”将错误的信息输出到/data/1.txt

[root@chengyinwu ~]# ls /ta 2> /data/1.txt

21.将/data/1.txt的文件内容,标准输出到/data/2.txt

[root@chengyinwu ~]# cat /data/1.txt > /data/2.txt

22.解释以下linux标准输入输出中文件描述符的含义

0 标准输入--->>>默认是键盘,也可以是文件或其他命令的输出
1 标准输出--->>>默认输出到屏幕
2 错误输出--->>>默认输出到屏幕

23.解释以下linux标准输入输出中符号的含义

<                                     输入重定向
<<                                   追加输入重定向
>                                    输出重定向
>>                                   追加输出重定向
2>                                  **错误覆盖输出重定向**
2>>                                  **错误追加输出重定向**
`&>`or `>&` or `2>&1`           **把标准输出和标准错误作为同一个数据流重定向到文件**
&>                                混合输出重定向
&>>                              **把标准输出和标准错误作为同一个数据流重追加重定向到文件**

24.使用"seq 10 50"将以0结尾的行标准输出到3.txt

[root@yinwucheng ~]# seq 10 50 |grep '0$' >3.txt

25.把/etc/fstab文件内容重定向到/tmp目录下文件名为fstab.out

[root@yinwucheng ~]# cat /etc/fstab > /tmp/fstab.out

26.把字符"hello world"追加到/tmp/fstab.out文件尾部

[root@yinwucheng ~]# echo "hello world" >> /tmp/fstab.out

猜你喜欢

转载自www.cnblogs.com/yinwu/p/11332375.html
今日推荐