zoukankan      html  css  js  c++  java
  • 面试题-4

    1.使用"ls -l /"以长格式查看根目录,显示头十位文件权限信息,写出每一位所代表的含义
    drwxr-xr-x
    d:目录
    rwx: 属主
    r-x: 属组
    r-x: 其他人
    rwx  ---->>>读写执行
    
    2.linux系统存放所有用户密码信息的文件是?
         /etc/shadow
         /etc/passwd
    
    3.存放用户账户信息的配置文件是?
        /etc/default/useradd
        /etc/login.defs
    
    4.改变文件所有者的命令为B
     A.chmod
     B.chown
     C.cat
     D.vim
    
    5.新建一个1.txt文件,文件内容如下
          1123
          1122
          112233
          321
          3306
          8080
          80
          23
          21
          8081
          8082
          8085
    (1)显示1.txt第3行到第10行的内容(三种方法)
    [root@chengyinwu ~]# sed -n '3,10p' 1.txt
    [root@chengyinwu ~]# tail 1.txt |head -8
    [root@chengyinwu ~]# awk 'NR==3,NR==10' 1.txt 
    
    (2)显示1.txt第3行和第10行的内容
    [root@chengyinwu ~]# awk 'NR==3 ||NR==10' 1.txt 
    [root@chengyinwu ~]# sed -n '3p;10p' 1.txt
    
    (3)新建用户oldboy,oldgirl,属同一用户组edu
    [root@chengyinwu ~]# groupadd edu
    [root@chengyinwu ~]# useradd oldboy -g edu
    [root@chengyinwu ~]# useradd oldgirl -g edu
    
    (4)修改文件1.txt的所有者为oldboy,属组为edu
    [root@chengyinwu ~]# chown oldboy.edu 1.txt
    
    (5)除所有者以外,属组和其他用户均没有任何权限(要求普通用户进行验证)
    mv 1.txt /tmp
    [root@chengyinwu ~]# chmod 600 /tmp/1.txt
    
    6.创建目录/web1,所有者是u1;创建目录/web2,所有者是u2,所属组是grp1。创建目录/web3,所属组是grp1
    [root@yinwucheng ~]# mkdir /web{1..3}
    [root@chengyinwu ~]# groupadd grp1
    [root@chengyinwu ~]# useradd u1
    [root@chengyinwu ~]# ll -d /web1/
    drwxr-xr-x 2 root root 4096 Aug  8 16:02 /web1/
    [root@chengyinwu ~]# chown u1 /web1/
    [root@chengyinwu ~]# ll -d /web1/
    drwxr-xr-x 2 u1 root 4096 Aug  8 16:02 /web1/
    
    
    [root@chengyinwu ~]# useradd u2 -g grp1
    [root@chengyinwu ~]# chown u2 /web2/
    [root@chengyinwu ~]# ll -d /web2/
    drwxr-xr-x 2 u2 grp1 4096 Aug  8 16:11 /web2/
    
    [root@chengyinwu ~]# mkdir /web3
    [root@chengyinwu ~]# chown .grp1 /web3/
    [root@chengyinwu ~]# ll -d /web3/
    drwxr-xr-x 2 root grp1 4096 Aug  8 16:13 /web3/
    
    7.当用户mysql对/data/DB目录无读权限,但是拥有写和执行权限,意味着能做哪些操作,无法做哪些操作?
    1.能进入目录 
    2.能创建新文件或目录
    3.删除文件或目录(需要知道文件)
    4.不能使用浏览目录的内容,也不能查看
    
    8.当用户mysql对/data/DB目录无写权限时,该目录下的只读文件file1是否可修改和删除?
        不能,因为对目录没有权限,所以不能。文件能不能删,不由文件决定,而由目录决定
    
    9.复制/etc/fstab文件到/var/tmp下,设置文件所有者为tomcat读写权限,所属组为apps组有读写权限,其他人无权限
    [root@chengyinwu ~]# cp /etc/fstab /var/tmp/
    [root@chengyinwu /var/tmp]# useradd tomcat
    [root@chengyinwu /var/tmp]# groupadd apps
    [root@chengyinwu /var/tmp]# chown tomcat.apps fstab
    [root@chengyinwu /var/tmp]# chmod 660 fstab
    
    11.将以下权限翻译成数字,将数字权限用字母表示
    rw-r-xr--   654
    rw-r--r--   644
    rwx--x--x   711
    rw-------   600
    rwxr--r--   744
    rw-rw-r--   664
    rwxrwxrwx   777 
    751   rwxr-x--x
    771   rwxrwx--x
    632   rw--wx-w-
    551   r-xr-x--x
    622   rw--w--w-
    746   rwxr--rw-
    644   rw-r--r--
    755   rwxr-xr-x
    

    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 -s 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 ~]# chown .A office_a/
    [root@yinwucheng ~]# chmod 770 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
    

    注意

    (1)建议先创建快照
    (2)有可能存在命令正确,但是查找不到文件的情况,是因为不存在相关条件的文件
    (3)如果存在命令正确,但是查找不到文件的情况,则先创建相关的文件、目录、用户、组,设置好对应的权限,再进行查找
    (4)如果是以时间为查找条件的题,则使用date命令修改linux系统时间为几天以前,创建好相关文件后再改回当前时间(date命令使用可参考https://blog.csdn.net/stalin_/article/details/80436568

    1.找出/tmp目录下,属主不是root,且文件名不以f开头的文件

    [root@chengyinwu ~]# find /tmp/ -type f ! -user root ! -name "f*"
    

    2.查找/etc/目录下,所有.conf后缀的文件

    [root@yinwucheng ~]# find /etc/ -type f -name "*.conf"
    

    3.查找/var目录下属主为root,且属组为mail的所有文件

    [root@yinwucheng ~]# find /var/ -type f -user root -group mail
    

    4.查找/var目录下7天以前,同时属主不为root,也不是postfix的文件

    [root@yinwucheng ~]# find /var/ -type f -mtime +7 ! -user root ! -user postfix
    

    5.查找/etc目录下大于1M且类型为普通文件的所有文件

    [root@yinwucheng ~]# find /etc/ -type f -size +1M
    

    6.查找/etc目录下所有用户都没有写权限的文件

    [root@yinwucheng ~]# find /etc/ -type f -perm a-w
    

    7.查找/目录下最后创建时间是3天前,后缀是*.log的文件

    [root@yinwucheng ~]# find / -type f -mtime -3 -name "*.log"
    

    8.查找/目录下文件名包含txt的文件**

    [root@yinwucheng ~]# find / -type f -name "*txt*"
    

    9.查找/目录下属主是oldboy并且属组是oldboy的文件

    [root@yinwucheng ~]# find / -type f -user oldboy -group oldboy
    
    

    10.查找/目录下属主是oldboy但是属组不是oldboy的文件

    [root@yinwucheng ~]# find / -type f -user oldboy ! -group oldboy
    
    

    11.查找/目录下属主是oldboy或者属主是oldgirl的文件

    [root@yinwucheng ~]# find / -type f -user oldboy -o -user oldgirl
    
    

    12.查找/tmp目录下属主既不是oldboy,也不是oldgirl的文件

    [root@yinwucheng ~]# find /tmp/ -type f ! -user oldboy ! -user oldgirl 
    
    

    13.查找/var/log目录下7天以前的文件

    [root@yinwucheng ~]# find /var/log/ -type f -mtime +7 
    
    

    14.查找/tmp目录下15天以前的文件删除

    [root@yinwucheng ~]# find /tmp/ -type f -mtime +15 |xargs rm -rf
    
    

    15.查找/home目录下,类型是目录的,并且属主是oldboy的目录

    [root@yinwucheng ~]# find /home/ -type d -user oldboy
    
    

    16.查找/var/log下大于100kb且以log结尾的所有文件

    [root@yinwucheng ~]# find /var/log/ -type f -size +100k -name "*log"
    
    

    17.查找tmp目录下所属组group1,所属主user1的目录

    [root@yinwucheng ~]# find /tmp/ -type d -group group1 -user user1
    
    

    18.同时查找根目录下名为1.txt,2.txt的文件和名字带a的目录

    [root@yinwucheng ~]# find / -type f -name "1.txt" -o -name "2.txt" -o -type d -name "*a*"
    
    

    19.查找/tmp目录下所有文件并删除

    [root@yinwucheng ~]# find /tmp/* -type f |xargs rm -rf
    
    
  • 相关阅读:
    DOM基础
    9个实用的Javascript代码高亮脚本
    去掉超链接虚线框去掉chrome浏览器中input或textarea在得到焦点时出现黄色边框和取消可以拖动大小
    我的Gvim配置文件
    收集的一些有关UED的团队和个人博客
    JS函数:返回下一个元素节点而不是下一个节点
    分享一款图片导航效果 Animated Slideshow Navigation
    原生javascript写的Tab菜单(函数版)
    单个select语句实现MySQL查询统计次数
    mysql 语句case when
  • 原文地址:https://www.cnblogs.com/yinwu/p/11369412.html
Copyright © 2011-2022 走看看