day 12 考试题机试


1.1创建/root/user /root/logs  /root/conf  /root/html目录,请用一条命令实现。
mkdir /root/{user,logs,conf,html}

1.2Linux关机重启及注销的命令有哪些 (每种至少两个)?
shutdows -h now 
init 0
reboot
init 6
logout
exit

1.3Linux中系统网卡的配置文件路径什么?
/etc/sysconfig/network-scriopts/ifcfg-eth0

1.4你知道哪些bash的快捷键呢?请把他写出来,并解释一下他的作用?(至少8个)
ctrl c 终止命令			ctrl z 程序后台执行
ctrl a 光标移动到命令行首   ctrl e 光标移动到行尾
ctrl w 删除上一个单词到空格的间隔 		ctrl l 清屏
ctrl d 退出当前bash

1.5网络类型都有哪几种?这几种模式,每个的含义你是怎么理解的?
nat 路由器模式 把物理机当成路由器不会与物理机ip冲突
桥接模式 直接与物理网络连接 会有可能于物理机ip冲突
仅主机模式 只能与主机进行通信

1.6找出系统中文件名以oldboy开头的所有文件,要求只能查找到/目录的前三级目录。?
find / -maxdepth 3 -type f -name 'oldboy*'

1.7Linux的发行版本都有哪些?(至少6个)
redhat 	centos debian linxu_mint fedora ubuntu

1.8怎样清除你所执行过的命令记录?
hisotry -c

1.9说明下面这几个文件的作用: /etc/resolv.conf、/etc/hosts、/var/log/messages、/var/log/secure。
 /etc/resolv.conf : dns配置解析文件		/etc/hosts:主机与ip关系映射文件
/var/log/messages: 系统日志文件			/var/log/secure:系统安全日志

1.10如何快速返回上一次所在的目录?
cd -

1.11欲把当前目录下的file1.txt复制为file2.txt 命令是,如果已存在该名称的文件名,怎么执行不会提示是否覆盖?
cp
cp 


1.12假设超级用户root当前所在目录为:/usr/local,键入cd命令后,用户当前所在目录为?
/root 

1.13创建/data/test目录,已知/data目录不存在,请给出命令?
mkdir -p /data/test

1.14在/root/目录下创建文件test.txt  test.log  test.sh  test.conf  请用一条命令创建。
touch /root/test.{txt,log,sh,conf}

1.15将/etc/passwd文件中的第一列和第七列的位置进行调换,以:号为分隔符。
[root@web01 ~]# head -1 /etc/passwd
root:x:0:0:root:/root:/bin/bash
head -1 /etc/passwd | awk -F: -vOFS=":" '{a=$1;$1=$7;$NF=a:print}'  

1.16如果我在当前在/目录下,之后执行了以下操作,请告诉我,最后我所在的目录位置?
cd /etc/sysconfig/
cd ..
cd ..
cd -
cd ~
cd ..
cd -
/root 或则 /home

1.17查看oldboy.txt文件中的内容,并显示行号。(至少两种方法)
grep -n '.*' oldboy.txt
cat -n oldboy.txt

1.18显示/etc/services文件的第11行到第20行的内容(至少两种方法)?
awk 'NR==11,NR==20' /etc/services
sed '11,20p' /etc/services

1.19已知文件123.txt内容如下,请过滤出不包含oldboy字符串的命令
test
OLDBOY
online
oldboy
online
oldboyoldboy
grep -v 'oldboy' 123.txt

1.20接上题,要求过滤出文件123.txt中包含online字符串的行,并统计过滤出来的内容共有多少行。
grep -c 'online' 123.txt

1.21调试系统服务时,希望能实时查看系统日志/var/log/messages的更新,如何做?
tail -f /var/log/messages     

1.22如何删除一个非空目录/opt?
rm -fr /opt

1.23统计/etc/passwd文件一共有多少行?(两种方法)
wc -l /etc/passwd 
grep -c '.*' /etc/passwd 

1.24已知软件包的链接地址为http://nginx.org/download/nginx-1.16.0.tar.gz,要求将其下载且下载之后的软件包名为nginx.tar.gz,如何执行命令。
wget -O ./nginx.tar.gz  http://nginx.org/download/nginx-1.16.0.tar.gz

1.25查找ifconfig命令的绝对路径在哪里?(两种方法)
whereis -b ifconfig
which ifconfig 

1.26统计文件/etc/services的字节数?(两种方法)
wc -c /etc/services
stat /etc/services

1.27执行下面的命令echo "Im qiuzengjia , is QQ 1176494252" >file.txt,要求取出该文件中的姓名和QQ号。(注意逗号前面有一个空格)(两种方法)。
awk -F '[, ]*' '{print$2,$5}' file.txt

1.28执行如下命令,要求去除重复的行,并统计出现的次数?
cat > file.txt <<EOF
abc
123
abc
123
def
EOF
sort file.txt | uniq -C 

1.29过滤出/etc/passwd以nologin结尾的内容,并统计行数。
grep -c '.*nologin' /etc/passwd

1.30使用cat和echo命令把oldboy oldgirl student三行内容(每个字符串是一行内容)写入到test.txt文件中
cat >> test.txt < eof
oldboy
oldgirl
student
eof

echo 'oldboy/noldgirl/nstudent' > test.txt

1.31以“:”为分隔符,取出/etc/passwd第一行的最后一列的内容?(两种方法)
head -1 /etc/passwd | cut -d ':' -f7
awk -F: '{print$7}' /etc/passwd

1.32已知执行ifconfig  eth0 结果如下:要求取出IP地址
[root@qiudao ~]# ifconfig  eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.19.186.20  netmask 255.255.240.0  broadcast 172.19.191.255	#前面有8个空格
        ether 00:16:3e:1a:18:44  txqueuelen 1000  (Ethernet)
ifconfig eth0 | sed -nr '2s#(.*et )(.*)( net.*)#2#gp'

1.33删除test.txt文件中的第10行到20行的内容。(两种方法)
sed -i '10,20d' test.txt
vim test.txt :10,20d

1.34取出test.txt文件中的第9行和第11行的内容(两种方法)
sed -nr '9p;11p' test.txt
awk 'NR==9;NR==11' test.txt

1.35统计nginx访问日志access.log中每个访问ip出现次数,显示最多的10个。(已知ip在第一列)
sed -nr 's#(.*)( - - .*$)#1#gp' access.log | sort | uniq -c | sort -nr | head -10

1.36过滤出/etc/services 文件包含3306或1521两数字所在的行的内容。(两种方法)
grep -E '3306|1521' /etc/services
sed -nr '/3306|1521/p' /etc/services


1.37排除/etc/ssh/sshd_config文件中的空行和注释行(以#开头的就是注释行)(两种方法)
sed -r '/^#|^s*$/d' /etc/ssh/sshd_config
awk '!/^#|^S*$/' /etc/ssh/sshd_config

1.38将/etc/passwd文件中第一行到第五行的root替换为admin?
sed -nr '1,5s#root#admin#gp' /etc/passwd

1.39在test.txt文件末尾插入test。(两种方法)
cat 'test' >> test.txt
echo 'test' >> test.txt

1.40写出redhat 中,配置网卡及dns 的配置文件是什么?并说明区别?
/etc/sysconfig/network-scripts/ifcfg-eth0  配置重启生效
/etc/resolv.conf   配置立即生效

1.41已知sort.log文件内容如下,请根据文件内容的第二列进行倒序排序。?
cat >>sort.log<<'EOF'
218.65.30.25 68652
218.65.30.53 34326
218.87.109.154 21201
112.85.42.103 18065
112.85.42.99 17164
218.87.109.151 17163
218.87.109.150 17163
218.65.30.61 17163
218.65.30.126 17163
218.65.30.124 17163
EOF
sort -nrk2 sort.log 

1.42已知文件test.txt内容如下,请给出输出test.txt文件内容时,不包含oldboy字符串的命令。
test
qiudao
oldboy
grep -v 'oldboy' test.txt

1.43找到/backup目录下所有后缀名为.txt的文件?
find /backup -type f -name '*.txt'

1.44把/etc/passwd文件中的:替换成# (两种方法)
sed -inr 's#:###g' /etc/passwd
tr ':' '#' /etc/passwd

1.45rm是个危险的命令,要求使用命令rm删除文件时提示“rm command no bny”,怎么实现?
alias rm="rm command no bny"

1.46取出下列文件的权限如:0644 ?(两种方法)
[root@qls ~]# stat  123.txt 
  File: ‘123.txt’
  Size: 44        	Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d	Inode: 67160518    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-07-27 16:55:57.055131412 +0800
Modify: 2019-07-27 16:55:50.098131214 +0800
Change: 2019-07-27 16:55:50.101131214 +0800
stat 123.txt | sed -nr '4s#(.*s: ()(.*)(/-r.*)#2#gp' 
stat 123.txt | awk -F '[(/]*' 'NR==4{print$2}'

1.47分别写出GNU和GPL是什么?
GNU 是自由软件基金会下的一个 软件操作系统开发项目 尊重使用则的权利 有emacs ide编写器 gcc编译器 bash命令解释器 hurd内核研发中
gawk 编程语言
GPL 通用公共许可协议

1.48把/etc/passwd文件中的oldboy替换成oldgirl。
sed -nri 's#oldboy#oldgril#gp' /etc/passwd

1.49显示/proc/meminfo文件中以s开头的行(忽略大小写)(两种方法)
grep -i '^s' /proc/meminfo 
sed -nr '/^s|^S/p' /proc/meminfo

1.50翻译题
01).command not found  			# 命令找不到		  
02).No such file or directory  	 # 不是一个文件或则目录
03).File exists  				# 文件不存在
04).Is a directory				# 这是一个目录
原文地址:https://www.cnblogs.com/xiaolang666/p/13346090.html