第一周作业 3月21日作业

常规题

1、用自己的语言简述计算机的组成

计算机系统由硬件系统和软件系统组成。

硬件系统包括:运算器、控制器、存储设备、输入设备和输出设备。

软件系统包括:系统软件和应用软件,系统软件是指计算机安装的各种操作系统;应用软件包括各种安装在操作系统上的实现不同用途的应用程序。


2、简单说明硬件、操作系统、应用软件与用户之间的关系

与硬件的关系:操作系统是位于硬件层上的第一层软件,它直接管理这计算机的硬件,合理组织计算机工作流程,并提高了硬件的利用率。

与其它系统软件的关系:操作系统是系统软件,但它不同于其它系统软件和应用软件,它为其它系统和应用软件提供接口。应用软件要使用操作系统所提供的服务方可方便使用计算机。

与用户之间的关系:操作系统是为改善人机界面、提供各种服务,为用户使用计算机提供良好运行环境的一种系统软件。


3、简述Linux哲学思想

一切都是一个文件(包括硬件)。

小型,单一用途的程序。

连接程序,共同完成复杂的任务(脚本)。

避免令人困惑的用户界面。

配置数据存储在文本中。


4、Linux系统中命令分为哪几种类型,请阐述其执行顺序

系统命令分为:内部命令和外部命令

命令执行顺序:别名 >  内部命令 > hash表 >外部命令(PATH变量)


5、用自己的语言尝试阐述什么叫重定向,并举例说明

重定向:将默认的输入、输出或错误对应的设备改变,指向新的目标

#把标准输出重定向到test.txt文件中

[root@centos8 ~]# echo "hello" > test.txt

[root@centos8 ~]# cat test.txt

hello

#向test.txt文件中追加内容

[root@centos8 ~]# echo "N53" >> test.txt

[root@centos8 ~]# cat test.txt

hello

N53

#如果test.txt文件中已有内容,覆盖test.txt文件中的内容

[root@centos8 ~]# echo "every" > test.txt

[root@centos8 ~]# cat test.txt

every

#把多条命令结果,重定向到一个文件中

[root@centos8 ~]# (ls ;hostname) > all.log

[root@centos8 ~]# cat all.log

all.log

all.txt

anaconda-ks.cfg

install_nginx.sh

centos7

#清除大文件

[root@centos8 ~]# dd if=/dev/zero of=bigfile bs=1M count=1024

1024+0 records in

1024+0 records out

1073741824 bytes (1.1 GB) copied, 1.58714 s, 677 MB/s

[root@centos8 ~]# ll -h bigfile

-rw-r--r-- 1 root root 1.0G Mar 21 20:52 bigfile

[root@centos8 ~]#cat /dev/null > bigfile

[root@centos8 ~]# ll -h bigfile

-rw-r--r-- 1 root root 0 Mar 21 20:52 bigfile

#把标准错误和标准输出,重定向到一个文件里

[root@centos8 ~]# ls /data xxx &> all.txt

[root@centos8 ~]# cat all.txt

ls: cannot access xxx: No such file or directory

/data:

magedu

nginx

#把把标准错误和标准输出,重定向到空设备里

[root@centos8 ~]# ls /data xxx &> /dev/null

#tr 输入重定向

[root@centos8 ~]# df

Filesystem    1K-blocks    Used Available Use% Mounted on

devtmpfs          487128      0    487128  0% /dev

tmpfs            497852      0    497852  0% /dev/shm

tmpfs            497852    8048    489804  2% /run

tmpfs            497852      0    497852  0% /sys/fs/cgroup

/dev/sda2      104806400 1651404 103154996  2% /

/dev/sda3      52403200 1007132  51396068  2% /data

/dev/sda1        1038336  134232    904104  13% /boot

tmpfs              99572      0    99572  0% /run/user/0

[root@centos8 ~]# df > df.log

[root@centos8 ~]# tr -s ' ' : < df.log

Filesystem:1K-blocks:Used:Available:Use%:Mounted:on

devtmpfs:487128:0:487128:0%:/dev

tmpfs:497852:0:497852:0%:/dev/shm

tmpfs:497852:8048:489804:2%:/run

tmpfs:497852:0:497852:0%:/sys/fs/cgroup

/dev/sda2:104806400:1651404:103154996:2%:/

/dev/sda3:52403200:1007132:51396068:2%:/data

/dev/sda1:1038336:134232:904104:13%:/boot

tmpfs:99572:0:99572:0%:/run/user/0

[root@centos8 ~]# echo 2^3 > bc.log

[root@centos8 ~]# cat bc.log

2^3

[root@centos8 ~]# bc < bc.log

8

#多行重定向

[root@centos8 ~]# cat > a.txt <<EOF

> HELLO

> n53

> EOF

[root@centos8 ~]# cat a.txt

HELLO

n53


场景题

1、领导老李在服务器上cat查看一个文件aa.txt,提示No such file or directory,让小王来帮忙看看是什么情况,小王一顿操作发现aa.txt是个链接文件,在备份服务器找到其原文件,不一会儿,小王就解决了老李查看aa.txt的问题,。请说明小王是如何解决的。

[root@centos8 ~]# touch aa.txt

[root@centos8 ~]# echo hello > aa.txt

[root@centos8 ~]# cat aa.txt

hello

[root@centos8 ~]# ln -s ../root/aa.txt /data/aa.txt

[root@centos8 ~]# ll /data/aa.txt

lrwxrwxrwx 1 root root 14 Mar 22 21:57 /data/aa.txt -> ../root/aa.txt

[root@centos8 ~]# mv /data/aa.txt /opt

[root@centos8 ~]# ll /opt

total 0

lrwxrwxrwx 1 root root 14 Mar 22 21:57 aa.txt -> ../root/aa.txt

[root@centos8 ~]# scp aa.txt 10.0.0.7:

The authenticity of host '10.0.0.7 (10.0.0.7)' can't be established.

ECDSA key fingerprint is SHA256:zb/8mo/ptS0h8eHVY1FDRuvh6aQj1opzpsD7khnYjSo.

Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

Warning: Permanently added '10.0.0.7' (ECDSA) to the list of known hosts.

root@10.0.0.7's password:

aa.txt                                                                              100%    6    3.7KB/s  00:00  00:00   

[root@centos7 ~]# ls

aa.txt

[root@centos8 ~]# rm -f aa.txt

[root@centos8 ~]# cat /opt/aa.txt

cat: /opt/aa.txt: No such file or directory

[root@centos8-2 ~]# ll /opt

total 0

lrwxrwxrwx 1 root root 14 Mar 22 21:57 aa.txt -> ../root/aa.txt


[root@centos7 ~]# scp aa.txt 10.0.0.8:

The authenticity of host '10.0.0.8 (10.0.0.8)' can't be established.

ECDSA key fingerprint is SHA256:8eD6mLtx6VPebzeGBEIJMs9np43gsQHfFAmvY7kleRI.

ECDSA key fingerprint is MD5:70:2a:b9:53:5d:97:53:9e:78:69:03:62:46:6d:db:c1.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '10.0.0.8' (ECDSA) to the list of known hosts.

root@10.0.0.8's password:

aa.txt                                                                              100%    6    7.5KB/s  00:00

[root@centos8 ~]# cat /opt/aa.txt

hello


2、用mail命令给自己的qq邮箱发送一份周末慰问信,截图给出结果

[root@centos8 ~]# cat .mailrc

set from=19661891@qq.com

set smtp=smtp.qq.com

set smtp-auth-user=19661891@qq.com

set smtp-auth-password=xxxxxxxxx  #这里是授权信息

set smtp-auth=login

set ssl-verify=ignore

[root@centos8 ~]# dnf -y install postfix mailx;systemctl enable --now postfix

[root@centos8 ~]# echo "Good weekend" | mail -s hello 19661891@qq.com


3、【选做】老李让小王安装一个收集日志的软件nxlog,需求是不允许root来运行nxlog这个程序,且被收集access.log其他用户无读取权限,三天后access.log会被nginx服务更新,即重新生成,文件名不变。为了正常收集,小王应该如何做?

(提示,该服务器已经安装了nxlog软件与nginx服务,即有nxlog、nginx同名的用户与用户组)

[root@centos8 ~]# mkdir /var/log/nginx

[root@centos8 ~]# touch /var/log/nginx/access.log

[root@centos8 ~]# ll /var/log/nginx/access.log

-rw-r--r-- 1 root root 0 Mar 21 21:36 /var/log/nginx/access.log

[root@centos8 ~]# useradd -s /sbin/nologin -r  nginx

[root@centos8 ~]# chown nginx.nginx /var/log/nginx/access.log

[root@centos8 ~]# ll

total 12

-rw-r--r--  1 root root    6 Mar 21 21:22 aa.txt

-rw-------. 1 root root 1306 Dec 21 17:04 anaconda-ks.cfg

-rw-r--r--  1 root root 3111 Mar 17 23:16 install_nginx.sh

[root@centos8 ~]# ll /var/log/nginx/access.log

-rw-r--r-- 1 nginx nginx 0 Mar 21 21:36 /var/log/nginx/access.log

[root@centos8 ~]# chmod 640 /var/log/nginx/access.log

[root@centos8 ~]# ll /var/log/nginx/access.log

-rw-r----- 1 nginx nginx 0 Mar 21 21:36 /var/log/nginx/access.log

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容