作业习题

1.打开这个网站http://nginx.org/download/,下载一个结尾为tar.gz的软件包
 wget  http://nginx.org/download/nginx-0.1.0.tar.gz 

2.同样打开上面的网站,下载一个结尾为tar.gz的软件包,要求下载之后的软件包名为nginx.tar.gz
wget -o  http://nginx.org/download/nginx-0.1.0.tar.gz  nginx.tar.gz

3.打开此网站https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/  下载一个结尾为rpm的软件包
wget https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.0-2.el7.x86_64.rpm

4.同样打开上面这个网站,下载一个结尾为rpm的软件包,要求下载之后的软件包名为zabbix.rpm
wget -o https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.0-2.el7.x86_64.rpm zabbix.rpm

5.在linux中访问邱老师的博客网站,访问主页就可以
curl https://www.increase93.com/
elinks --dump www.increase93.com

6.在linux中访问邱老师的博客网站,要求把主页的内容保存到qls.html文件中。
curl -os https://www.increase93.com/ qls.html
[root@linux10 ~]# elinks --dump www.increase93.com | cat > qls.html

7.在linux中访问百度的首页
[root@linux10 ~]# elinks --dump www.baidu.com

8.在linux中访问百度的首页,要求把主页的内容保存到baidu.html文件中
[root@linux10 ~]# links --dump www.baidu.com | cat > baidu.com

9.把/etc/hosts文件下载到本地电脑桌面
[root@linux10 ~]# sz /etc/hosts

10.把/etc/services文件下载到本地电脑D盘中
[root@linux10 ~]# sz /etc/services /d 

11.把你的课堂笔记上传到linux系统中
[root@linux10 ~]# rz   

12.把你的习题笔记上传到linux系统中的/opt目录下面
cd /opt
rz

13.如果我要把本地电脑中的目录上传到linux系统,请问怎么上传?
用xftp



14.查找ifconfig命令的绝对路径在哪里?你能使用几种方法实现?

[root@linux10 ~]# whereis -b ifconfig
ifconfig: /usr/sbin/ifconfig

[root@linux10 ~]# which ifconfig
/usr/sbin/ifconfig

[root@linux10 ~]# type -p ifconfig
/usr/sbin/ifconfig

[root@linux10 ~]# find / -type f -name 'ifconfig'
/usr/sbin/ifconfig



15.查找netstat命令的绝对路径在哪里?你能使用几种方法实现?
netsat:[root@linux10 ~]# which netstat
/usr/bin/netstat

[root@linux10 ~]# whereis -b netstat
netstat: /usr/bin/netstat

[root@linux10 ~]# find / -maxdepth 3 -type f -name 'netstat'
/usr/bin/netstat



16.统计文件/etc/hosts的行数?你能使用几种方法实现?

[root@linux10 ~]# grep -c '.*' /etc/hosts
2

[root@linux10 ~]# cat -n /etc/hosts | tail -1
     2	::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

[root@linux10 ~]# wc -l /etc/hosts
2 /etc/hosts



17.改变bash的提示符实际上就是改变变量?

PS1



写一个文件,文件内容如下,下面39-45题请用该文件作答?

cat >>test.txt<<EOF
server {
	lisTEN 80;
	server_nAme www.oldboy.com;
	root /code/dOcs
	index INDEX.html;
}
EOF
18.过滤www.oldboy.com这段关键字

[root@linux10 ~]# grep -n 'www.oldboy.com' test.txt
3:server_nAme www.oldboy.com;

[root@linux10 ~]# grep -w 'www.oldboy.com' test.txt
server_nAme www.oldboy.com;

 [root@linux10 ~]# grep -o 'www.oldboy.com' test.txt
www.oldboy.com



19.同时过滤出root和index的行,不区分大小写

[root@linux10 ~]# grep -iE 'root|index' test.txt
root /code/dOcs
index INDEX.html;



20.过滤index,区分大小写

[root@linux10 ~]# grep -o 'index' test.txt
index

[root@linux10 ~]# grep -w 'index' test.txt
index INDEX.html;



21.过滤出带"O"的行,不区分大小写

[root@linux10 ~]# grep -in 'o' test.txt
3:server_nAme www.oldboy.com;
4:root /code/dOcs



22.过滤出不带";"的行

[root@linux10 ~]# grep -v ';' test.txt
server {
root /code/dOcs
}

23.过滤出以s开头的行p

[root@linux10 ~]# grep '^s' test.txt
server {
server_nAme www.oldboy.com;



24.统计该文件的行数

[root@linux10 ~]# grep -c '.*' test.txt
6

[root@linux10 ~]# wc -l test.txt
6 test.txt

25.如果某一天你误操作了"rm -rf *",会发生哪些情况

删除当前目录下的所有文件

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

rm -i 

27.设置rm命令存在别名之后,要删除/oldboy这个目录,怎么实现?

[root@linux10 ~]# usr/bin/rm /oldboy



28.已知123.txt文件内容如下:
zenglaoshi
qiulaoshi
oldboy 
要求过滤出oldboy这一行的内容?你有几种方法?

[root@linux10 ~]# grep 'oldboy' 123.txt
oldboy



29.接上题,要求不显示oldboy这行内容,怎么实现?你有几种方法?

[root@linux10 ~]# grep -v 'oldboy' 123.txt
zenglaoshi
qiulaoshi



1.显示“I'm a student”到屏幕上面

echo “I'm a student”



2.将“I'm a student”追加到hello.txt文件中

[root@linux10 ~]# echo Im a student >> hello.txt



3.查看oldboy.txt文件中的内容,并显示行号(请使用cat命令)。

[root@linux10 ~]# cat -n oldboy.txt



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

[root@linux10 ~]# cat > test.txt <<eof

> oldboy 
> oldgirl
> studen
> eof

5.查看系统中/etc/services文件中的内容(使用more和less命令,进行上下页查看,并搜索关键字‘ssh’,之后退出。)



6.显示/etc/passwd文件的前5行内容。

[root@linux10 ~]# head -5 /etc/passwd

7.显示/etc/passwd文件的最后5行内容。

[root@linux10 ~]# tail -5 /etc/services



8.显示/etc/services文件的第11行到第20行的内容

[root@linux10 ~]# head -20 /etc/services | tail -10



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

[root@linux10 ~]# grep 'oldboy' 123.txt
oldboy
oldboyoldboy

10.过滤出文件123.txt中不包含test的行,并给其过滤出来的内容加上行号

[root@linux10 ~]# grep -vn 'test' 123.txt
2:OLDBOY
3:online
4:oldboy
5:oldboyoldboy

11.要求过滤出文件123.txt中包含oldboy的字符串,忽略大小写。

[root@linux10 ~]# grep -i 'oldboy' 123.txt
OLDBOY
oldboy
oldboyoldboy

12.要求过滤出文件123.txt中包含online字符串的行,并统计共有多少行。

[root@linux10 ~]# grep 'online' 123.txt
online
[root@linux10 ~]# grep 'online' 123.txt | wc -l
1

13.要求过滤出文件123.txt中包含oldboy的单词。

[root@linux10 ~]# grep -w 'oldboy' 123.txt
oldboy

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

[root@linux10 ~]# tailf /var/log/messages



15.打印配置文件/etc/passwd内容的行号及内容,你有几种方法可以实现?

[root@linux10 ~]# cat -n /etc/passwd

[root@linux10 ~]# grep -n '.*' /etc/passwd



16.查找出ifconfig命令的路径,你能使用几种方法查找出来。

[root@linux10 ~]# whereis -b ifconfig
ifconfig: /usr/sbin/ifconfig
[root@linux10 ~]# which ifconfig
/usr/sbin/ifconfig
[root@linux10 ~]# type -p ifconfig
/usr/sbin/ifconfig
[root@linux10 ~]# find / -type f -name 'ifconfig'
/usr/sbin/ifconfig



17.查看系统中的cd命令是不是内嵌命令

[root@linux10 ~]# type -a cd
cd is a shell builtin
cd is /usr/bin/cd

18.找出系统中文件名为oldboy.txt的所有文件。

[root@linux10 ~]# locate oldboy.txt
/opt/oldboy.txt

19.找出系统中名为oldboy的所有目录。

[root@linux10 ~]# locate oldboy.txt
/opt/oldboy.txt

[root@linux10 ~]# find / -type d -name 'oldboy.txt'
/opt/oldboy.txt

20.找出系统中文件名以oldboy开头的所有文件,要求只能查找到/目录的前三级目录。

[root@linux10 ~]# find / -maxdepth 3  -type d -name 'oldboy*'