linux第一章和第三章命令

1、分别用cat \tac\nl三个命令查看文件/etc/ssh/sshd_config文件中的内容,并用自己的话总计出这三个文档操作命令的不同之处?

[root@localhost ~]# cat /etc/ssh/sshd_config

#$OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm Exp $

#This is the sshd server system-wide configuration file.  See

#sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/usr/bin

(cat是正着显示内容)

[root@localhost ~]# tac /etc/ssh/sshd_config

#       ForceCommand cvs server

#       PermitTTY no

#       AllowTcpForwarding no

#       X11Forwarding no

#Match User anoncvs

# Example of overriding settings on a per-user basis

(tac是倒着显示内容)

[root@localhost ~]# nl /etc/ssh/sshd_config

1       #       $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm Exp $

2       # This is the sshd server system-wide configuration file.  See

3       # sshd_config(5) for more information.

4       # This sshd was compiled with PATH=/usr/local/bin:/usr/bin

5       # The strategy used for options in the default sshd_config shipped with

6       # OpenSSH is to specify options with their default value where

7       # possible, but leave them commented.  Uncommented options override the

8       # default value.

(nl不仅显示文件内容,还显示文件的行号)

2、分别用more和less查看/etc/ssh/sshd_config里面的内容,请用总结more和less两个命令的相同和不同之处?

[root@localhost ~]# more /etc/ssh/sshd_config

#       $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm Exp $

# This is the sshd server system-wide configuration file.  See

# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/usr/bin

(全屏方式分页显示文件内容)

[root@localhost ~]# less /etc/ssh/sshd_config

#$OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm Exp $

# This is the sshd server system-wide configuration file.  See

# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/usr/bin

(less不仅全屏方式分页显示文件内容,比more命令扩展功能更多)

3、将/etc/passwd文件中的前20行重定向保存到/root下改名为20_pass.txt,将/etc/passwd文件中的后15行重定向保存到/root下改名为:pass_15.txt

[root@localhost ~]# head -20 /etc/passwd > /root/20_pass.txt

[root@localhost ~]# ls

10.txt       20.txt  4.txt  7.txt  anaconda-ks.cfg  模板  文档  桌面

1.txt        2.txt   5.txt  8.txt  liyurui          视频  下载

20_pass.txt  3.txt   6.txt  9.txt  公共             图片  音乐

[root@localhost ~]# tail -15 /etc/passwd > /root/pass_15.txt

[root@localhost ~]# ls

10.txt       20.txt  4.txt  7.txt  anaconda-ks.cfg  公共  图片  音乐

1.txt        2.txt   5.txt  8.txt  liyurui          模板  文档  桌面

20_pass.txt  3.txt   6.txt  9.txt  pass_15.txt      视频 

4、请用一个命令统计/etc/hosts文件包含有多少行?多少字节?多少单词数?

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

2 /etc/hosts

[root@localhost ~]# wc -c /etc/hosts

158 /etc/hosts

[root@localhost ~]# wc -w /etc/hosts

10 /etc/hosts

5、练习使用grep和egrep

5.1.通过grep管道工具过滤出ifconfig命令显示信息中的IP字段?

[root@localhost ~]# ifconfig | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'

192.168.100.133

255.255.255.0

192.168.100.255

127.0.0.1

255.0.0.0

5.2.将/etc/passwd文件中的前20行重定向保存到/root下名称为pass?

[root@localhost ~]# head -20 /etc/passwd > /root/pass

[root@localhost ~]# ls

10.txt       20.txt  4.txt  7.txt  anaconda-ks.cfg  pass_15.txt  视频  下载

1.txt        2.txt   5.txt  8.txt  liyurui          公共         图片  音乐

20_pass.txt  3.txt   6.txt  9.txt  pass             模板  

5.3.过滤/etc/passwd文件中含有/sbin/nologin 的行并统计行数?

[root@localhost ~]# grep -n "/sbin/nologin" /etc/passwd

2:bin:x:1:1:bin:/bin:/sbin/nologin

3:daemon:x:2:2:daemon:/sbin:/sbin/nologin

4:adm:x:3:4:adm:/var/adm:/sbin/nologin

5:lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

9:mail:x:8:12:mail:/var/spool/mail:/sbin/nologin

10:operator:x:11:0:operator:/root:/sbin/nologin

11:games:x:12:100:games:/usr/games:/sbin/nologin

12:ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin

[root@localhost ~]# grep  -c "/sbin/nologin" /etc/passwd

35

5.4 过滤/etc/passwd文件中以sh结尾的行,及以 root开头的行,不显示包含login的行?

[root@localhost ~]# grep "sh$" /etc/passwd | grep "^root" |grep -v "login"

root:x:0:0:root:/root:/bin/bash

5.5 分别用grep和egrep过滤出/etc/ssh/sshd_config文件中不包含“#”开头和空白的行?

[root@localhost ~]# grep -v "^#" /etc/ssh/sshd_config|grep -v "^$"

HostKey /etc/ssh/ssh_host_rsa_key

HostKey /etc/ssh/ssh_host_ecdsa_key

HostKey /etc/ssh/ssh_host_ed25519_key

SyslogFacility AUTHPRIV

AuthorizedKeysFile .ssh/authorized_keys

PasswordAuthentication yes

ChallengeResponseAuthentication no

GSSAPIAuthentication yes

GSSAPICleanupCredentials no

UsePAM yes

X11Forwarding yes

UsePrivilegeSeparation sandbox             # Default for new installations.

AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES

AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT

AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE

AcceptEnv XMODIFIERS

Subsystem       sftp  /usr/libexec/openssh/sftp-server

[root@localhost ~]# egrep -v "^#|^$" /etc/ssh/sshd_config

HostKey /etc/ssh/ssh_host_rsa_key

HostKey /etc/ssh/ssh_host_ecdsa_key

HostKey /etc/ssh/ssh_host_ed25519_key

SyslogFacility AUTHPRIV

AuthorizedKeysFile .ssh/authorized_keys

PasswordAuthentication yes

ChallengeResponseAuthentication no

GSSAPIAuthentication yes

GSSAPICleanupCredentials no

UsePAM yes

X11Forwarding yes

UsePrivilegeSeparation sandbox             # Default for new installations.

AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES

AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT

AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE

AcceptEnv XMODIFIERS

Subsystem       sftp  /usr/libexec/openssh/sftp-server

6.1 通过tar命令将/etc/passwd文件打包压缩成/root/file.tar.gz

 [root@localhost ~]# tar -czf /root/file.tar.gz /etc/passwd

tar: 从成员名中删除开头的“/”

[root@localhost ~]# ls

10.txt       2.txt  6.txt  anaconda-ks.cfg  pass_15.txt  视频  音乐

1.txt        3.txt  7.txt  file.tar.gz      z            图片  桌面

20_pass.txt  4.txt  8.txt  liyurui          公共         文档

20.txt       5.txt  9.txt  pass             模板         下载

6.2通过tar命令将/etc/passwd文件打包压缩成/root/file.tar.bz2

[root@localhost ~]# tar -cjf /root/file.tar.bz2 /etc/passwd
tar: 从成员名中删除开头的“/”
[root@localhost ~]# ls
10.txt       20.txt  4.txt  7.txt  anaconda-ks.cfg  file.tar.gz          npass.gz     z     视频  下载
1.txt        2.txt   5.txt  8.txt  file2.tar.gz     httpd-2.2.17.tar.gz  pass         公共  图片  音乐
20_pass.txt  3.txt   6.txt  9.txt  file.tar.bz2     liyurui              pass_15.txt  模板

6.3创建空文件夹/web/test1,并将file.tar.bz2 解包并释放到/web/test1目录下?

[root@localhost ~]# tar -xf file.tar.bz2 -C /web/test1

[root@localhost ~]# ls

[root@localhost ~]# cd /web/test1
[root@localhost test1]# ls
etc

7.1 通过vi编辑/web/test1/passwd文件将文件里为root单词全部替换成benet。

benet:x:0:0:benet:/benet:/bin/bash

:s/root/benet/g

7.2 通过vi编辑 删除pass文件第1、5、10行。

光标移动在第一行,然后按Esc键进入命令模式,然后按:键进入末行模式,输入dd 删除第一行。

1 root:x:0:0:root:/root:/bin/bsh(前)

1 bin:x:1:1:bin:/bin:/sbin/nologin(后)

  光标移动在第五行,然后按Esc键进入命令模式,然后按:键进入末行模式,输入dd 删除第五行。

5 sync:x:5:0:sync:/sbin:/bin/sync(前) 

5 bin:x:1:1:bin:/bin:/sbin/nologin(后)

光标移动在第十行,然后按Esc键进入命令模式,然后按:键进入末行模式,输入dd 删除第十行。

10 games:x:12:100:games:/usr/games:/sbin/nologin(前)

10 ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin(后)

7.3 在vi中显示pass文件行号复制文件2 3 4行粘贴到以lp开头的行下。

按Esc键进入命令模式,按:键进入末行模式,输入set nu 显示行号

     1 root:x:0:0:root:/root:/bin/bsh

      2 bin:x:1:1:bin:/bin:/sbin/nologin

      3 daemon:x:2:2:daemon:/sbin:/sbin/nologin

      4 adm:x:3:4:adm:/var/adm:/sbin/nologin

      5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

      6 bin:x:1:1:bin:/bin:/sbin/nologin

(将光标放在第二行,按yy复制,然后将光标移动到IP行,按p粘贴)

1 root:x:0:0:root:/root:/bin/bsh

      2 bin:x:1:1:bin:/bin:/sbin/nologin

      3 daemon:x:2:2:daemon:/sbin:/sbin/nologin

      4 adm:x:3:4:adm:/var/adm:/sbin/nologin

      5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

      6 daemon:x:2:2:daemon:/sbin:/sbin/nologin

(将光标放在第三行,按yy复制,然后将光标移动到IP行,按p粘贴)

1 root:x:0:0:root:/root:/bin/bsh

      2 bin:x:1:1:bin:/bin:/sbin/nologin

      3 daemon:x:2:2:daemon:/sbin:/sbin/nologin

      4 adm:x:3:4:adm:/var/adm:/sbin/nologin

      5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

      6 adm:x:3:4:adm:/var/adm:/sbin/nologin

(将光标放在第四行,按yy复制,然后将光标移动到IP行,按p粘贴)

7.4 通过vi编辑 查找文件内包含mail var等字符串,并记录所在行号。

    按Esc键进入命令模式,按:键进入末行模式,输入set nu  ,显示出行号

10 mail:x:8:12:mail:/var/spool/mail:/sbin/nologi

(按Esc键进入命令模式,按:键进入末行模式,输入/mail

     1 root:x:0:0:root:/root:/bin/bsh

      2 bin:x:1:1:bin:/bin:/sbin/nologin

      3 daemon:x:2:2:daemon:/sbin:/sbin/nologin

      4 adm:x:3:4:adm:/var/adm:/sbin/nologin

      5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

      6 sync:x:5:0:sync:/sbin:/bin/sync

      7 bin:x:1:1:bin:/bin:/sbin/nologin

      8 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

      9 halt:x:7:0:halt:/sbin:/sbin/halt

     10 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin

     11 operator:x:11:0:operator:/root:/sbin/nologin

     12 games:x:12:100:games:/usr/games:/sbin/nologin

     13 ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin

     14 nobody:x:99:99:Nobody:/:/sbin/nologin

     15 dbus:x:81:81:System message bus:/:/sbin/nologin

     16 polkitd:x:999:999:User for polkitd:/:/sbin/nologin

     17 tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin

     18 usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin

     19 colord:x:998:997:User for colord:/var/lib/colord:/sbin/nologin

     20 ntp:x:38:38::/etc/ntp:/sbin/nologin

     21 libstoragemgmt:x:997:995:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin

~                                                                                                           

~                                                                                                            

~                                                                                                           

~                                                                                                            

~                                                                                                           

~                                                                                                           

~                                                                                                            

~                                                                                                           

/var

(按Esc键进入命令模式,按:键进入末行模式,输入/var

7.5 通过vi编辑 快速跳转到文件的第二行,通过r 读取 /etc/hosts 文件的内容到第二行下。

    2 bin:x:1:1:bin:/bin:/sbin/nologin(按2G键

     2 bin:x:1:1:bin:/bin:/sbin/nologin

     3 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

      4 ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

(将光标移动到2行,按:键进入末行命令,输入r /etc/hosts

7.6将更改后的文件使用vim另存为/root/new_pass。

(按:键进入末行模式,输入 w /etc/hosts

[root@localhost ~]# ls

10.txt       20.txt  4.txt  7.txt  anaconda-ks.cfg  file.tar.gz  pass         公共  图片  音乐

1.txt        2.txt   5.txt  8.txt  file2.tar.gz     liyurui      pass_15.txt  模板  文档  桌面

20_pass.txt  3.txt   6.txt  9.txt  file.tar.bz2     new_pass     z            视频  下载

7.7将new_pass文件压缩成gz格式并改名为npass.gz文件。

[root@localhost ~]# gzip new_pass

gzip: new_pass: No such file or directory

[root@localhost ~]# ls

10.txt       20.txt  4.txt  7.txt  anaconda-ks.cfg  file.tar.gz  pass         公共  图片  音乐

1.txt        2.txt   5.txt  8.txt  file2.tar.gz     liyurui      pass_15.txt  模板  文档  桌面

20_pass.txt  3.txt   6.txt  9.txt  file.tar.bz2     new_pass.gz  z            视频  下载

[root@localhost ~]# mv new_pass.gz npass.gz

[root@localhost ~]# ls

10.txt       20.txt  4.txt  7.txt  anaconda-ks.cfg  file.tar.gz  pass         公共  图片  音乐

1.txt        2.txt   5.txt  8.txt  file2.tar.gz     liyurui      pass_15.txt  模板  文档  桌面

20_pass.txt  3.txt   6.txt  9.txt  file.tar.bz2     npass.gz     z            视频  下载

8.统计/dev 目录下的文件数量。

[root@localhost ~]# ls -l /dev |grep -v "^d"|wc -l

138

9.1在/boot下查找文件名以vmlinuz开头的文件?

[root@localhost ~]# find /boot -name "vmlinuz*"

/boot/vmlinuz-3.10.0-229.el7.x86_64

/boot/vmlinuz-0-rescue-b6811c6a1fb6475cbb05d3315db53c95

9.2在/boot下查找文件大小大于3M 小于 20M 的文件

[root@localhost ~]# find /boot -size +3M -a -size -20M

/boot/vmlinuz-3.10.0-229.el7.x86_64

/boot/vmlinuz-0-rescue-b6811c6a1fb6475cbb05d3315db53c95

/boot/initramfs-3.10.0-229.el7.x86_64.img

10 请详细写出构建本地yum仓库的步骤?并在每行命令后面用自己的话做上中文注释?

[root@localhost ~]# umount /media/   //卸载/media/下已挂载到光盘

umount: /media/:未挂载

[root@localhost ~]# mount /dev/sr0 /media/    //将第一张光盘挂载到/media/目录下

mount: /dev/sr0 写保护,将以只读方式挂载

[root@localhost ~]# ls /media/          //查看/media/目录

CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7

EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL

[root@localhost ~]# cd /etc/yum.repos.d/    //进入yum仓库本地目录

[root@localhost yum.repos.d]# ls          //查看yum仓库本地目录

CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo

CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Vault.repo

[root@localhost yum.repos.d]# mkdir a     //在yum仓库本地目录里建立 a目录

[root@localhost yum.repos.d]# mv C* a    //将所有C开头的文件转移到a的目录下

[root@localhost yum.repos.d]# ls         //查看Yum 仓库本地目录,里面是a

a

[root@localhost yum.repos.d]# vi local.repo  //编辑local.repo文件

([cdrom]    //仓库名称

name=cdrom

baseurl=file:///media   //指定rpm包的位置

enabled=1   //启用本地yum仓库

gpgcheck=0  //禁用gpg校验

[root@localhost yum.repos.d]# yum -y clean all   //清除yum缓存

已加载插件:fastestmirror, langpacks

正在清理软件源: cdrom

Cleaning up everything

[root@localhost yum.repos.d]# yum makecache  //重建yum缓存

 [root@localhost yum.repos.d]# rpm -q vsftpd   //查询是否安装vsftpd

未安装软件包 vsftpd

[root@localhost yum.repos.d]# yum -y install vsftpd //用yum安装vsftpd

 [root@localhost yum.repos.d]# rpm -q vsftpd //查询是否安装vsftpd

vsftpd-3.0.2-9.el7.x86_64

[root@localhost yum.repos.d]# yum -y remove vsftpd//用yum卸载vsftpd

[root@localhost yum.repos.d]# rpm -q vsftp//查询是否卸载vsftpd

未安装软件包 vsftp

11、用yum命令安装vsftpd,查询安装情况,最后卸载vsftpd,并再次查询卸载情况?

[root@localhost ~]# yum -y install vsftpd

[root@localhost ~]# yum -y remove vsftpd

12、用rpm命令安装vsftpd,查询安装情况,最后卸载vsftpd,并再次查询卸载情况?

[root@localhost Packages]# rpm -i vsftpd-3.0.2-9.el7.x86_64.rpm

警告:vsftpd-3.0.2-9.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY

[root@localhost Packages]# rpm -q vsftpd

vsftpd-3.0.2-9.el7.x86_64

[root@localhost Packages]# rpm -e vsftpd

[root@localhost Packages]# rpm -q vsftpd

未安装软件包 vsftpd

13、通过源码方式通过解包、配置、编译、安装四个步骤安装源码软件httpd-2.2.17.tar.gz?并进行测试

[root@localhost ~]#yum -y install gcc      //用yum命令安装gcc

[root@localhost ~]#yum -y install gcc-c++  //用yum命令安装gcc-c++

[root@localhost ~]#yum -y install make    //用yum命令安装make

[root@localhost ~]#yum -y install lynux    //用yum命令安装lynux

[root@localhost ~]# tar -xf httpd-2.2.17.tar.gz -C /usr/src  //将httpd-2.2.17.tar.gz解包到/usr/src

[root@localhost local]#mkdir apache       //进入local目录里面再建一个apache目录

[root@localhost ~]# cd  /usr/src/httpd-2.2.17//进入httped-2.2.17.tar.gz文件

[root@localhost httpd-2.2.17]# ./config --prefix=/usr/local/apache//选择软件安装目录

[root@localhost httpd-2.2.17]# make//执行make命令,进行编译

[root@localhost httpd-2.2.17]# make install//执行make install命令,进行安装

[root@localhost httpd-2.2.17]#cd /usr/local/apache/conf///切换目录

[root@localhost httpd conf]#cp httpd.conf httpd.conf.bak //将httpd.conf 改为httpd.conf.bak

[root@localhost httpd-2.2.17]#vi/usr/local/apache/conf/httpd.conf//进入httpd.conf文件编辑(将里面的#ServerName www.example.com:80复制yy,粘贴p)

[root@localhost ~]#/usr/local/apache/bin/apachectl star//启动Apache

[root@localhost ~]#lynx 127.0.0.1 //输入lynux 127.0.0.1

已加载插件:fastestmirror, langpacks

Loading mirror speeds from cached hostfile

正在解决依赖关系

--> 正在检查事务

---> 软件包 lynx.x86_64.0.2.8.8-0.3.dev15.el7 将被 安装

--> 解决依赖关系完成

依赖关系解决

=============================================================================================================

 Package              架构                   版本                                源                     大小

=============================================================================================================

正在安装:

 lynx                 x86_64                 2.8.8-0.3.dev15.el7                 cdrom                 1.4 M

事务概要

=============================================================================================================

安装  1 软件包

总下载量:1.4 M

安装大小:5.4 M

Downloading packages:

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  正在安装    : lynx-2.8.8-0.3.dev15.el7.x86_64                                                          1/1

  验证中      : lynx-2.8.8-0.3.dev15.el7.x86_64                                                          1/1

已安装:

  lynx.x86_64 0:2.8.8-0.3.dev15.el7                                                                          

完毕!

猜你喜欢

转载自www.cnblogs.com/liyurui/p/11251880.html
今日推荐