面试题-6

1.查找根目录下所有的隐藏目录

[root@chengyinwu ~]# find / -type d -name ".*"

2.查找根目录下以rpm结尾的所有文件

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

3.查找/data/bak目录下15天以前的文件删除(自行修改系统时间模拟相关环境)

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

4.使用“ mount /dev/cdrom /mnt/ ” 挂载光盘,进入到/mnt/Packages目录,查找该目录是否存在带有关键字“tree”和“vsftpd”的软件包

[root@yinwucheng ~]# mount /dev/cdrom /mnt/
[root@yinwucheng ~]# cd /mnt/Packages/
[root@yinwucheng /mnt/Packages]# rpm -qa |grep -E 'tree|vsftpd'
tree-1.6.0-10.el7.x86_64
vsftpd-3.0.2-25.el7.x86_64

5.使用rpm命令安装tree这个软件。

[root@yinwucheng /mnt/Packages]# rpm -ivh tree-1.6.0-10.el7.x86_64.rpm

6.查看你的服务器中是否安装httpd这个软件。

[root@yinwucheng /mnt/Packages]# rpm -q httpd

7.接上题,如果没有请用rpm进行安装。

[root@yinwucheng /mnt/Packages]# yum install httpd

8.启动httpd这个服务,然后用你的10.0.0.0这个网段的IP在浏览器上面进行访问,看看是否有结果,如果没有,请关闭你的防火墙

[root@yinwucheng /mnt/Packages]# systemctl start httpd
[root@yinwucheng /mnt/Packages]# systemctl stop firewalld
[root@yinwucheng /mnt/Packages]# systemctl disable firewalld

9.查看httpd这个软件包里面的内容。

[root@yinwucheng /mnt/Packages]# rpm -ql httpd

10.查看httpd这个软件的配置文件是哪个

[root@yinwucheng /mnt/Packages]# rpm -qc httpd
/etc/httpd/conf/httpd.conf

11.查看httpd这个软件包的详细信息。

[root@yinwucheng /mnt/Packages]# rpm -qi httpd

12.查看一下netstat这个命令属于哪个软件包

[root@yinwucheng /mnt/Packages]# yum provides netstat
net-tools-2.0-0.24.20131004git.el7.x86_64

13.查看你的服务器中是否安装sl这个命令,如果有请进行删除,没有就先安装在删除。

[root@yinwucheng /mnt/Packages]# rpm -qa sl
sl-5.02-1.el7.x86_64
[root@yinwucheng /mnt/Packages]# rpm -e sl

14.联网下载mongodb这个软件,版本号为3.0.0

[root@yinwucheng /mnt/Packages]# rpm -ivh https://mirrors.aliyun.com/mongodb/yum/redhat/7/mongodb-org/3.0/x86_64/RPMS/mongodb-org-mongos-3.0.0-1.el7.x86_64.rpm

15.将mongodb这个软件版本升级为4.0.0

[root@yinwucheng /mnt/Packages]# rpm -Uvh https://mirrors.aliyun.com/mongodb/yum/redhat/7/mongodb-org/4.0/x86_64/RPMS/mongodb-org-mongos-4.0.0-1.el7.x86_64.rpm

16.列举一下rpm的常用参数有哪些

选项 描述
-i 安装rpm
-v 显示安装详细信息
-h 显示安装rpm进度
选项 描述
rpm -q 查看指定软件包是否安装
rpm -qa 查看系统中已安装的所有RPM软件包列表
rpm -qi 查看指定软件的详细信息
rpm -ql 查询指定软件包所安装的目录、文件列表
rpm -qc 查询指定软件包的配置文件
rpm -qf 查询文件或目录属于哪个RPM软件

下面几题请使用yum命令

17.yum安装rsync这个软件。

[root@chengyinwu ~]# yum install rsync -y

18.安装多个软件,例如sl、lsof、net-tools、nmap等

[root@chengyinwu ~]# yum install sl lsof net-tools nmap -y

19.删除sl这个命令

[root@chengyinwu ~]# yum remove sl -y

20.查看一下ping这个命令属于哪个软件包

[root@chengyinwu ~]# yum provides ping
iputils-20160308-10.el7.x86_64

21.查看你的服务器中有哪些可用的yum源仓库。

[root@chengyinwu ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                                  repo name                                                              status
base/7/x86_64                            CentOS-7                                                               10,019
epel/x86_64                              Extra Packages for Enterprise Linux 7 - x86_64                         13,343
extras/7/x86_64                          CentOS-7                                                                  435
updates/7/x86_64                         CentOS-7                                                                2,500
repolist: 26,297

1.把你系统中原有的base源更新为阿里云的源

[root@yinwucheng ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

2.在你的系统中增加一个epel源,请使用阿里云的镜像

[root@yinwucheng ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

3.给系统添加一个zabbix的源的仓库

方法一:手动配置zabbix源
[root@yinwucheng /etc/yum.repos.d]# vim zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
-----------------------------------------------------------------------------------------
方法二:直接安装
rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm

4.把你系统中的base和epel源改成清华源的镜像

1.将以下内容写入 /etc/yum.repos.d/CentOS-Base.repo
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$ba
search/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basear
ch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus
/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basear
ch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

2.yum install epel-release

5.简单下载一个命令ntpdate

[root@yinwucheng ~]# yum install ntpdate -y

6.更新ntpdate这个命令的版本

[root@yinwucheng ~]# yum   update ntpdate

7.卸载系统中的ntpdate这个命令

[root@yinwucheng ~]# yum remove ntpdate -y

8.显示系统中可用的yum源仓库

[root@yinwucheng ~]# yum repolist

9.显示系统中所有以tre开头的软件包

[root@yinwucheng ~]# yum list |grep "^tre*"

10.显示系统中可更新的软件包

[root@yinwucheng ~]# yum check-update

11.显示系统中已经安装过得软件包

[root@yinwucheng ~]# yum list installed

12.查看net-tools这个软件包的详细信息

[root@yinwucheng ~]# rpm -qi net-tools

13.查看scp这个命令来源于哪个软件包。

[root@yinwucheng ~]# yum provides scp
openssh-clients-7.4p1-16.el7.x86_64

14.清理本地的软件包缓存

[root@yinwucheng ~]# yum clean packages

15.查看一下nginx这个软件包都依赖哪些软件

方法一:
[root@yinwucheng ~]# yum install nginx -y
Dependency Installed:
  dejavu-fonts-common.noarch 0:2.33-6.el7                      dejavu-sans-fonts.noarch 0:2.33-6.el7                 
  fontconfig.x86_64 0:2.13.0-4.3.el7                           fontpackages-filesystem.noarch 0:1.44-8.el7           
  gd.x86_64 0:2.0.35-26.el7                                    gperftools-libs.x86_64 0:2.6.1-1.el7                  
  libX11.x86_64 0:1.6.5-2.el7                                  libX11-common.noarch 0:1.6.5-2.el7                    
  libXau.x86_64 0:1.0.8-2.1.el7                                libXpm.x86_64 0:3.5.12-1.el7                          
  libxcb.x86_64 0:1.13-1.el7                                   nginx-all-modules.noarch 1:1.12.2-3.el7               
  nginx-filesystem.noarch 1:1.12.2-3.el7                       nginx-mod-http-geoip.x86_64 1:1.12.2-3.el7            
  nginx-mod-http-image-filter.x86_64 1:1.12.2-3.el7            nginx-mod-http-perl.x86_64 1:1.12.2-3.el7             
  nginx-mod-http-xslt-filter.x86_64 1:1.12.2-3.el7             nginx-mod-mail.x86_64 1:1.12.2-3.el7  
--------------------------------------------------------------------------------------------------------------
方法二:
[root@yinwucheng ~]# yum deplist nginx

16.查看yum的历史记录

[root@yinwucheng ~]# yum history

17.了解一下yum的包组有关的命令参数

yum groups list               查看系统的组包
yum groups install +包名 -y    安装组包
yum remove +包名 -y            删除组包

18.总结一下yum命令的常用参数。

   yum install    安装软件
​	yum remove     卸载软件
​	yum list       列出所有安装与未安装的软件包
​	yum provides   查看命令属于哪个软件包
​	yum repolist   列出yum源可用的软件仓库
​	yum update     升级所有软件(包括内核及所有设置)

​	yum history     查看历史执行的yum命令
​	yum clean all packages     清除缓存的软件包
​	yum makecache              生成缓存
​	yum reinstall              覆盖安装
​	-y                         遇到是否选项则默认选择yes

19.把你的base和epel的源改成阿里云的镜像源。

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

20.自主搭建一个本地yum仓库,书写好操作过程,rpm包可以使用磁盘镜像中的rpm包。

1.关闭防火墙与selinux
systemctl stop firewalld
setenforce 0
2.挂载镜像
mount /dev/cdrom /mnt
3.将本地的所有源打成压缩包
cd /etc/yum.repos.d/
gzip *
4.建立本地仓库
vim /etc/yum.repos.d/centos.d
[centos]
name = centos
baseurl = file:///mnt
gpgcheck = 0
enabled = 1
5.清除缓存
yum clean all
6.验证本地仓库
yum list
rpm -qa
yum install vsftpd -y

一、基础(每题 2 分)

1.1 阐述绝对路径与相对路径的区别

  • 绝对路径:只要从根 / 开始的路径都算是绝对路径; 例如:/a.txt
  • 相对路径:相对于当前的路径, 例如:.a.txt

1.2 简述软连接与硬连接的区别

  • 软链接:相当于快捷方式,不同的inode指向一个block,删除源文件则软链接失效
  • 硬链接:相当于做备份,相同的inode指向同一个block,删除源文件对硬链接无影响

1.3 简述命令执行的流程

  • 首先看命令是不是通过绝对路径的方式执行
  • 第二看命令是否存在别名设置
  • 第三查看命令是内置命令还是外置命令
  • 第四命令若是内置,可直接执行,若是外置命令,查看是否存在缓存 hash
  • 最后通过$PATH变量查找命令,若查到,则可以正常执行,若没有,则会报错 commant not found

1.4 写出查询 file.txt 以 abc 结尾的行

grep 'abc$' file.txt

1.5 查找 file.log 文件中的包含关键字 “helloworld”的内容,及其上下两行的重定向到 1.txt

grep -C 2 'helloworld' file.log > 1.txt

1.6 假设公司研发部的用户 David 和 Peter 属于组 A

1.6.1 建立相应的用户和组,并设置相应的对应关系

groupadd A
useradd David -g A
useradd Peter -g A

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

mkdir yf_a
chown .A yf_a yf_a
chmod 770 yf_a

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

mkdir yf_b
chown David.A yf_b
chmod 720 yf_b

1.7 有一用户 oldboy,及用户组 oldboy,在code 目录下创建的所有文件自动归属于 oldboy 组所有

groupadd oldboy
useradd oldboy -g oldboy
mkdir code
chown .oldboy code
chmod g+s code

1.8 有两个用户组 python 及 Linux,python组可以修改读取/hom/python/目录下所有内容,但 不能让 Linux 组读取;Linux 组可以修改读取 /home/linux/目录下所有文件,但不能让 python 组读取。给出配置命令。

groupadd python
groupadd Linux

mkdir /hom/python/
chown .python /hom/python/
chmod 770 /hom/python

mkdir /home/linux/
chown .Linux /home/linux/
chmod 770 /home/linux/

二、find 相关(每题 3 分)

2.1 找出/tmp目录下,属主不是 root 的文件

find /tmp -type f ! -user root

2.2 查找/var目录下属主为 old,且属组为 boy的文件

find /var -type f -user old -g boy

2.3 查找/var目录下 7 天以前修改、且属组为root 的文件

find /var -type f -mtime +7 -group root

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

find /etc -type f -size +1M 

2.5 查找/etc/目录下大于 100k,小于 1M 的文 件

find /etc/ -type f -size +100k -size -1M

2.6 查找/目录下文件名包含 txt 的文件

find / -type f -name "*txt"

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

find / -type f -user oldboy -o -group oldgirl

2.8 删除/tmp目录下 15 天前的文件

find /tmp -type f -mtime +15 |xargs rm -rf

2.9 查找根下名为 1.txt 或 2.txt 的文件

find / -type f -name "1.txt" -o -name "2.txt"

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

find /tmp/* -type f |xargs rm -rf

三、tar 相关(每题 3 分)

3.1 使用 zip 打包/etc 目录。

zip -r etc.zip /etc 

3.2 用 zip 打包/opt 目录,要求不显示打包过程。

zip -q -r opt.zip /opt

3.3 解压/data/etc.zip到当前目录

unzip /data/etc.zip

3.4 已知文件 oldboy.zip,在不解压的情况下,如何查看该文件的内容

zcat oldboy.zip

3.5 将/data/old.tar.gz 解压到/opt 目录下

tar xf /data/old.tar.gz -C /opt

3.6 不解压的情况下,查看/data/old.tar.gz 包中都有什么内容

tar tf /data/old.tar.gz

3.7 打包/etc/目录,要求不打包/etc/hosts这个文件。

tar etc.tar.gz /etc --exclude=/etc/hosts

3.8 打包/etc/目录,要求不打包/etc/hosts和/etc/passwd这两个文件。

tar etc.tar.gz /etc --exclude=/etc/hosts --exclude=/etc/passwd

3.9 打包/etc/目录,命令以ip 地址方式的压缩包:比如:10.0.0.200_etc.tar.gz

tar $(ifconfig eth0 |awk 'NR==2 {print $2}')_etc.tar.gz /etc

3.10 打包/etc/目录,要求以.bz2格式

tar cjf etc.bz2 /etc 

四、软件安装相关(每题3 分)

4.1 使用rpm 命令安装 tree 软件。

rpm -ivh tree +版本号

4.2 查看你的服务器中是否安装httpd 这个软件。

rpm -q httpd

4.3 查看httpd 软件包里面的内容。

rpm -ql httpd

4.4 查看httpd 软件包的详细信息。

rpm -qi httpd

4.5 查看一下netstat 这个命令属于哪个软件包

yum provides netstat

4.6 卸载sl 这个命令

rpm -e sl

4.7 已知服务的mongodb 的版本为 3.0,现将mongodb这个软件版本升级为4.0,请给出 rpm升级命令

rpm -Uvh +最新版本号

4.8 yum 安装 rsync 这个软件。

yum install rsync -y

4.9 yum 安装多个软件,例如 sl、lsof、net-tools、nmap 等

yum install sl lsof net-tools nmap -y

4.10 查看你的服务器中有哪些可用的 yum 源仓库。

yum repolist

五、进阶(每题4 分)

5.1 将“I am student”重定向到/root/bgx1.txt中

echo "I am student" > /root/bgx1.txt

5.2 简述源码编译的流程

1.下载源码包
2.解压
3. ./configure配置
4.编译
5.安装
6.软件软链接
7.运行
8.测试

5.3 查找/etc/目录下以.conf结尾、修改时间为最近七天的文件,打包压缩为/tmp/conf.tar.gz

tar zcvf /tmp/conf.tar.gz  $(find  /etc/ -type f -mtime -7 -name "*.conf")

5.4 查找/目录下以a 开头的目录,打包压缩为zip结尾的压缩包

find / -type d -name "a*" -exec zip {} a.zip ;

5.5 查找/目录下,属主为oldboy 的文件,复制到/home/oldboy/目录下

find / -type f -user oldboy -exec cp {} /home/oldboy/

六、翻译(每题2 分)

6.1 [root@test-200 ~]# cd /rot

-bash: cd: /rot: No such file or directory

6.2 [root@test-200 ~]# mdkir a

-bash: mdkir: command not found

6.3 [root@test-200 ~]# mkdir a

mkdir: cannot create directory ‘a’: File exists 6.4

[root@test-200 ~]# rm a

rm: cannot remove ‘a’: Is a directory

6.5 [root@test-200 ~]#rm a.txt

rm:remove regular empty file ‘a.txt’?

6.6 [root@test-200 ~]# cp /tmp/a.txt /root/a.txt

cp:overwrite ‘/root/a.txt’?

6.7 [root@test-200 ~]# id www

id: www: no such user

6.8[test@test-200 /]$ cd /root

bash: cd:/root: Permission denied

6.9 [root@test-200 /tmp]# cp -q a.txt c.txt

cp: invalidoption -- 'q'

6.10 [root@test-200 /home]# useradd test

useradd: user'test' already exists

原文地址:https://www.cnblogs.com/yinwu/p/11369432.html