Linux-06-Linux基础总结及练习题

一、总结

总结

基础总结

二、练习题1

查看/etc/目录下所有文件及目录包括隐藏文件
	ls /etc -la

在oldboy目录下进入根目录下的etc目录下的yum.repos.d目录

	cd /etc/yum.repos.d/

在家目录下创建一个名为oldboy的目录,然后进入该目录

	cd ~
	mkdir oldboy
	cd oldboy

在oldboy下创建一个名为student.txt的文件

	touch student.txt

查看根目录下etc下passwd文件所有内容						
	cat /etpasswd
	
	
删除一个非空目录/oldboy

	rm -rf /oldboy/*


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

	ls /etc/*.conf
	find /etc -type f -name "*.conf"

复制/oldboy目录到/tmp目录下

	cp /oldboy /tmp/


移动/oldgirl目录到/tmp目录下

	mv /oldgirl /tmp/
	

将/etc/hosts文件用tar格式打包

	tar czf etc_host.tar.gz /etc/hosts

将/var/log/目录解压到/opt目录中

	tar czf log.tar.gz /var/log/
	tar xf log.tar.gz -C /opt/


yum安装rsync这个软件

	yum install rsync -y
	

卸载sl这个命令
	yum remove sl -y


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

	rpm -ql net-tools

使用yum安装一个nginx并启动,查看nginx进程的详细信息

	yum install nginx -y
	rpm -ql nginx


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

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



已知文件oldboy.zip,请问在不解压的情况下,怎样查看该文件的内容。

	unzip -l etc.zip

打包/etc/目录,命令以ip地址+当前时间方式的压缩包: 比如: 10.0.0.98_2019-4-23_etc.tar.gz

	tar czf $(ifconfig ens32 | awk 'NR==2 {print $2}')_$(date +%F)_etc.tar.gz /etc
	

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

	rpm -ivh tree-----xxxxxx


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

	rpm -q httpd
	rpm -qa | grep httpd


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



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

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



简单下载一个命令ntpdate

	yum install ntpdate


有文件内容如下,要求列出不以199或者200开头的IP地址
Interface                Physical              Protocol             IP Adderss
Eth1/0/1                       up                    up             199.11.250.1
Eth1/0/2                       up                    up             200.11.250.5
Loop0                          up                    up(s)          199.11.250.2
Vlan1                          *down                 down           unassigned
Vlan500                        down                  down           139.100.1.56
Vlan900                        up                    up             139.100.1.57
Vlan1000                       up                    up             149.11.233.1
	
[root@oldboy-pythonedu ~]# awk '{print $4}' net.txt  | grep -Ev "^199|^200"

	
查看系统日志/var/log/messages所使用磁盘空间的大小
du -sh /var/log/messages


匹配/etc/passwd里包含root关键字的行(要求至少两种方法,分别使用awk和grep)

	grep "root" /etc/passwd
	awk '/root/' /etc/passwd


以“:”为分隔符,取出/etc/passwd第一行的最后一列的内容

	awk -F ':' '{print $1,$NF}' /etc/passwd


取出以“:”为分隔符,第三列(用户UID)以0结尾的
	
	awk -F ':' '{print $1,$3}' /etc/passwd | grep "0$"


新建用户u1、u2,密码是redhat,属于同一个附加组grp1,用户u2不允许登陆到系统中
	groupadd grp1
	useradd u1 -G grp1 
	useradd u2 -G grp1  -s /sbin/nologin 
	echo "redhat" | passwd --stdin u1 &>/dev/null
	echo "redhat" | passwd --stdin u2 &>/dev/null



查看用户u1的uid和gid信息

	id u1


创建组distro,其GID为2019
	groupadd distro -g 2019


创建用户olddir,其ID号为1005,基本组为distro
useradd olddir -u 1005 -g distro
id olddir


给用户oldman添加密码,密码为oldboyedu
useradd oldman
echo "oldboyedu" | passwd --stdin oldman

(mv)命令可以移动目录或文件,还可以为文件或目录重命名。

选择题

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

在使用mkdir命令创建新的目录时,在其父目录不存在时先创建父目录的选项是(-p)
-m
-d
-f
-p

在linux中,(A)命令不是针对目录操作的。
A. Ps
B. cd
C.pwd
D. ls

欲把当前目录下的file1.txt复制为file2.txt 正确的命令是() cp file1.txt file2.txt  cat file1.txt > file2.txt
copy file1.txt file2.txt
cp file1.txt file2.txt
cat file2.txt file1.txt
cat file1.txt > file2.txt

建立一个新文件可以使用的命令为: touch
chmod
more
cp
touch

如果要列出一个目录下的所有文件需要使用命令行( ls -a   ll -a )
ls -l
ls
ls -a
ls -d
ll -a 

除非特别指定,cp假定要拷贝的文件在下面那个目录下( 当前目录)
用户目录
home目录
root目录
当前目录

rm命令可以删除目录和文件,其主要差别就是是否使用(-r)参数。


(多选)Linux创建文件的命令有( touch   vi/vim  > )
ls
touch
cat
vi/vim
>

用"rm -i"系统会提示什么来让你确认( 是否真的删除 )
命令行的每个选项
是否真的删除
是否有写的权限
文件的位置

在下列命令中,不能显示文本文件内容的命令是( join )
more
less
tail
head
cat
tac
join

三、练习题2

(一)选择题(每题2分)	 

1.1 设超级用户root当前所在目录为:/usr/local,键入cd命令后, 
用户当前所在目录为(B)
A:/home     B:/root       C:/home/root    D:/usr/local
1.2 Linux有三种查看文件的命令,若希望在查看文件内容过程中可以用光标上下移动来查看文件内容,应使用命令(C)
A:cat       B:more       C:less          D:me
1.3 在Linux系统中,用来存放系统所需要的配置文件和子目录是(A)
A:/etc       B:/var        C:/root       D:/home
1.4 Linux文件系统的文件都安其作用分门别类地放在相关目录中,对于外部设备文件,一般应将其放在(C)目录中
A:/bin       B:/etc       C:/dev       D:/lib
1.5 除非特别指定,cp假定要拷贝的文件在下面那个目录下( D) 
A:用户目录    B:home目录     C:root目录     D:当前目录
1.6 在vi编辑器中的命令模式下,键入(B)可在光标当前所在行下添加一新行。
A:a         B:o        C:I         D:A
1.7 ( D)命令可以从文本文件的每一行中截取指定内容的数据。 
A:cp       B:dd       C:fmt       D:cut
1.8 按下(A)键能终止当前运行的命令	 
A:ctrl -c      B:ctrl -f       C:ctrl -b       D:ctrl -d
1.9 在给定文件中查找与条件相符字符串的命令及查找某个目录下相应文件的命令为:A
A:grep    B:gzip       C:find
(二)原理题	 

2.1 bash常用快捷键(2分)
	 
2.2 常见的bash特性有哪些?(2分)

2.4 以下目录的作用(7.5分)

2.6 什么是绝对路径,什么是相对路径(2分)	
 
 2.8 vim的几种模式,每种模式都是做什么的(2分)

2.9 写出15个学过的命令(15分)	 
mkdir touch cd pwd ls cp mv rm cat head less more rz sz wget unzip zip gzip tar yum rpm cut awk grep sed sort uniq file which whreis id useradd groupadd userdel groupdel  wc chown chmod

2.10 以下特殊符号所代表的含义(2.5分)	
^
$
.*
+

(三)命令题	 
3.1 创建目录/old/boy/(2分)	 
3.2 使用一条命令在/old/boy/目录下创建bgx1.txt、bgx2.txt、 bgx3.txt三个文件(2分) 

Touch /oldboy/bgx{1..3}.txt
3.3 将/old/boy/目录下所有内容复制到/root/目录下(2分)
Cp -rp /oldboy/* /root
	 
3.4 将/old目录移动到/tmp/下(2分)	 mv


3.5 将I am student输入到/root/bgx1.txt中(2分)	
Vim
Echo “i am student” >> /root/bgx1.txt 
3.6 查看/root/bgx1.txt文件的内容(四种方法)(4分)	
Cat less more head tail  tac 
3.7 查看/tmp/old/属于哪种文件类型(2分)	 
3.8 删除/tmp目录下所有内容(2分)	 
Rm -rf /tmp/*
3.9 删除/root下所有a开头的文件(2分)	 a*
3.10 查看/etc/passwd文件的第7、8行(3分)
[root@oldboy-pythonedu ~]# awk 'NR>6 && NR<9' 1.txt
[root@oldboy-pythonedu ~]# head -8 1.txt  | tail -2
	 
3.11 清除命令历史记录(3分)	
History -c 
3.12 将文件从Windows上传到centos系统中使用什么命令(3分)
rz 
3.13 如何将/root/bgx1.txt文件下载到windows系统中(3分) 
sz
3.14 如何比较两个文件内容有什么区别(2种方式,并简述2种方式的区别)(6分)
Diff vimdiff

3.15 已知阿里源地址为http://mirrors.aliyun.com/repo/Centos-7.r epo将其下载到etc/yum.repos.d目录下并命名为Centos-7.repo(3 分)

3.16 如何安装vim(3分)	 

3.18 如何查看家目录下的所有文件(3分)
Ls -a

3.19 给hello设置别名,使每次使用hello就输出“你好”(3分) 
Alias hello=’echo “你好”’
3.20 取消hello命令的别名(3分)	 
Unalias hello
(四)面试题
4.1 显示1.txt文件第3到第10行的内容?(3分)	 
[root@oldboy-pythonedu ~]# head -10 1.txt  | tail -8
4.2 写出查询file.txt以abc结尾的行(3分)
[root@oldboy-pythonedu ~]# grep "abc$" 1.txt
4.3 删除file.txt文件中的空行(3分)	
[root@oldboy-pythonedu ~]# sed -i '/^$/d' 1.txt
 4.4 找出ifconfig命令结果中的1-255之间的数值;(3分)
 
4.5 统计出apache的access.log 中访问最多的5个ip(IP为第一列)(4分) 

4.6 在/var/ sync/log/cef_watchd-20080424.1og文件中查找大小写不敏感“mysql"字符串中的命令是(3分) 
Grep -i “mysql” /var/ sync/log/cef_watchd-20080424.1og

4.7 用命令行更改config.txt文件,把里面所有的"name"更改为"address" (4分)
Sed -i ‘s#name#address#g’config.txt


4.9 显示file文件里匹配foo字串那行及前5行、匹配foo及后5行(4分)
[root@oldboy-pythonedu ~]# grep -C 5 "foo" 1.txt


4.10 查找file.log文件中的包含关键字“helloworld”的内容,及其上下两行的内容从定向保存到1.txt。请写出命令(4分)
[root@oldboy-pythonedu ~]# grep -C 5 "foo" 1.txt  > 3.txt

猜你喜欢

转载自blog.csdn.net/qq_45957580/article/details/108985558