【Linux】sed文本处理及软件管理

2021/8/9 7:05:50

本文主要是介绍【Linux】sed文本处理及软件管理,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

软件管理

1、编译安装http2.4,实现可以正常访问

  安装编译相关工具包

root@mirror-centos8-p11 ~]# yum install gcc make autoconf apr-devel apr-util-devel pcredevel -y

  下载并解压  httpd-2.4.48.tar.gz

[root@mirror-centos8-p11 ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.48.tar.gz
[root@mirror-centos8-p11 ~]# tar xvf httpd-2.4.48.tar.gz
[root@mirror-centos8-p11 ~]# ls
anaconda-ks.cfg  httpd-2.4.48  httpd-2.4.48.tar.gz  ps1.bak  setup.sh  system_info.sh

  生成安装配置内容: 将安装目录设置在 /data/httpd,配置文件路径 /etc/httpd

[root@mirror-centos8-p11 ~]# cd httpd-2.4.48/
[root@mirror-centos8-p11 httpd-2.4.48]# ls
ABOUT_APACHE     build            CMakeLists.txt  httpd.dep   InstallBin.dsp  Makefile.in    README            srclib
acinclude.m4     BuildAll.dsp     config.layout   httpd.dsp   LAYOUT          Makefile.win   README.CHANGES    support
Apache-apr2.dsw  BuildBin.dsp     configure       httpd.mak   libhttpd.dep    modules        README.cmake      test
Apache.dsw       buildconf        configure.in    httpd.spec  libhttpd.dsp    NOTICE         README.platforms  VERSIONING
apache_probes.d  CHANGES          docs            include     libhttpd.mak    NWGNUmakefile  ROADMAP
ap.d             changes-entries  emacs-style     INSTALL     LICENSE         os             server
[root@mirror-centos8-p11 httpd-2.4.48]#./configure --prefix=/data/httpd --sysconfdir=/etc/httpd

  进行编译,编译过程出错:

  gcc: error: /usr/lib/rpm/redhat/redhat-hardened-ld: No such file or directory
[root@mirror-centos8-p11 httpd-2.4.48]# make
......
gcc: error: /usr/lib/rpm/redhat/redhat-hardened-ld: No such file or directory
make[4]: *** [/root/httpd-2.4.48/modules/aaa/modules.mk:2: mod_authn_file.la] Error 1
make[4]: Leaving directory '/root/httpd-2.4.48/modules/aaa'
make[3]: *** [/root/httpd-2.4.48/build/rules.mk:117: shared-build-recursive] Error 1
make[3]: Leaving directory '/root/httpd-2.4.48/modules/aaa'
make[2]: *** [/root/httpd-2.4.48/build/rules.mk:117: shared-build-recursive] Error 1
make[2]: Leaving directory '/root/httpd-2.4.48/modules'
make[1]: *** [/root/httpd-2.4.48/build/rules.mk:117: shared-build-recursive] Error 1
make[1]: Leaving directory '/root/httpd-2.4.48'
make: *** [/root/httpd-2.4.48/build/rules.mk:75: all-recursive] Error 1


查看缺失文件来源
[root@mirror-centos8-p11 httpd-2.4.48]# yum provides /usr/lib/rpm/redhat/redhat-hardened-ld
Last metadata expiration check: 0:35:42 ago on Sun 08 Aug 2021 08:23:31 PM CST.
redhat-rpm-config-125-1.el8.noarch : Red Hat specific rpm configuration files
Repo        : AppStream
Matched from:
Filename    : /usr/lib/rpm/redhat/redhat-hardened-ld

安装缺失的组件
[root@mirror-centos8-p11 httpd-2.4.48]# yum install redhat-rpm-config-125-1.el8.noarch -y

  重新进行编译,编译成功未出现报错提示

[root@mirror-centos8-p11 httpd-2.4.48]# make
.......
/usr/lib64/apr-1/build/libtool --silent --mode=compile gcc  -pthread      -DLINUX -D_REENTRANT -D_GNU_SOURCE     -I. -I/root/httpd-2.4.48/os/unix -I/root/httpd-2.4.48/include -I/usr/include/apr-1 -I/root/httpd-2.4.48/modules/aaa -I/root/httpd-2.4.48/modules/cache -I/root/httpd-2.4.48/modules/core -I/root/httpd-2.4.48/modules/database -I/root/httpd-2.4.48/modules/filters -I/root/httpd-2.4.48/modules/ldap -I/root/httpd-2.4.48/modules/loggers -I/root/httpd-2.4.48/modules/lua -I/root/httpd-2.4.48/modules/proxy -I/root/httpd-2.4.48/modules/http2 -I/root/httpd-2.4.48/modules/session -I/root/httpd-2.4.48/modules/ssl -I/root/httpd-2.4.48/modules/test -I/root/httpd-2.4.48/server -I/root/httpd-2.4.48/modules/md -I/root/httpd-2.4.48/modules/arch/unix -I/root/httpd-2.4.48/modules/dav/main -I/root/httpd-2.4.48/modules/generators -I/root/httpd-2.4.48/modules/mappers -prefer-pic -c mod_alias.c && touch mod_alias.slo
/usr/lib64/apr-1/build/libtool --silent --mode=link gcc  -pthread           -o mod_alias.la -rpath /data/httpd/modules -module -avoid-version  mod_alias.lo 
/usr/lib64/apr-1/build/libtool --silent --mode=compile gcc  -pthread      -DLINUX -D_REENTRANT -D_GNU_SOURCE     -I. -I/root/httpd-2.4.48/os/unix -I/root/httpd-2.4.48/include -I/usr/include/apr-1 -I/root/httpd-2.4.48/modules/aaa -I/root/httpd-2.4.48/modules/cache -I/root/httpd-2.4.48/modules/core -I/root/httpd-2.4.48/modules/database -I/root/httpd-2.4.48/modules/filters -I/root/httpd-2.4.48/modules/ldap -I/root/httpd-2.4.48/modules/loggers -I/root/httpd-2.4.48/modules/lua -I/root/httpd-2.4.48/modules/proxy -I/root/httpd-2.4.48/modules/http2 -I/root/httpd-2.4.48/modules/session -I/root/httpd-2.4.48/modules/ssl -I/root/httpd-2.4.48/modules/test -I/root/httpd-2.4.48/server -I/root/httpd-2.4.48/modules/md -I/root/httpd-2.4.48/modules/arch/unix -I/root/httpd-2.4.48/modules/dav/main -I/root/httpd-2.4.48/modules/generators -I/root/httpd-2.4.48/modules/mappers -prefer-pic -c mod_rewrite.c && touch mod_rewrite.slo
/usr/lib64/apr-1/build/libtool --silent --mode=link gcc  -pthread           -o mod_rewrite.la -rpath /data/httpd/modules -module -avoid-version  mod_rewrite.lo 
make[4]: Leaving directory '/root/httpd-2.4.48/modules/mappers'
make[3]: Leaving directory '/root/httpd-2.4.48/modules/mappers'
make[2]: Leaving directory '/root/httpd-2.4.48/modules'
make[2]: Entering directory '/root/httpd-2.4.48/support'
make[2]: Leaving directory '/root/httpd-2.4.48/support'

make[1]: Leaving directory '/root/httpd-2.4.48'
  进行编译安装
[root@mirror-centos8-p11 httpd-2.4.48]# make install
......
Building shared: mod_vhost_alias.la mod_negotiation.la mod_dir.la mod_actions.la mod_speling.la mod_userdir.la mod_alias.la mod_rewrite.la
make[4]: Entering directory '/root/httpd-2.4.48/modules/mappers'
make[4]: Nothing to be done for 'local-shared-build'.
make[4]: Leaving directory '/root/httpd-2.4.48/modules/mappers'
make[3]: Leaving directory '/root/httpd-2.4.48/modules/mappers'
make[2]: Leaving directory '/root/httpd-2.4.48/modules'
make[2]: Entering directory '/root/httpd-2.4.48/support'
make[2]: Leaving directory '/root/httpd-2.4.48/support'

Installing configuration files
mkdir /etc/httpd
mkdir /etc/httpd/extra
mkdir /etc/httpd/original
mkdir /etc/httpd/original/extra
Installing HTML documents
mkdir /data/httpd/htdocs
Installing error documents
mkdir /data/httpd/error
Installing icons
mkdir /data/httpd/icons
mkdir /data/httpd/logs
Installing CGIs
mkdir /data/httpd/cgi-bin
Installing header files
mkdir /data/httpd/include
Installing build system files
mkdir /data/httpd/build
Installing man pages and online manual
mkdir /data/httpd/man
mkdir /data/httpd/man/man1
mkdir /data/httpd/man/man8
mkdir /data/httpd/manual
make[1]: Leaving directory '/root/httpd-2.4.48'

  配置环境,将程序运行路径写入环境变量配置,并刷新生效

[root@mirror-centos8-p11 bin]# echo "PATH=//data/httpd/bin:$PATH" > /etc/profile.d/httpd.sh
[root@mirror-centos8-p11 bin]# source /etc/profile.d/httpd.sh 
[root@mirror-centos8-p11 bin]# 

  创建用户 apache,设定用户目录为  /data/httpd/www ,指定使用apache 运行 httpd 服务

[root@mirror-centos8-p11 bin]# useradd -r -s /sbin/nologin -d /data/httpd/www -c Apache -u 80 apache

[root@mirror-centos8-p11 httpd]# sed -ri.bak -e "s/daemon$/apache/g" /etc/httpd/httpd.conf 
[root@mirror-centos8-p11 httpd]# cat /etc/httpd/httpd.conf | grep "^[(User)|(Group)]"
User apache
Group apache
[root@mirror-centos8-p11 httpd]# 

  启动服务

[root@mirror-centos8-p11 ~]# apachectl start
[root@mirror-centos8-p11 ~]# 

  打开浏览器验证服务

 

 

 

2、基于已安装完成的 httpd 服务,搭建私有yum仓库,分别为引用 网络源和本地源

 基于网络源(Zabbix)

  配置httpd默认路径 /data/httpd/www

[root@mirror-centos8-p11 ~]# cat /etc/httpd/httpd.conf | grep "/data/httpd"
ServerRoot "/data/httpd"
DocumentRoot "/data/httpd/htdocs"
<Directory "/data/httpd/htdocs">
    ScriptAlias /cgi-bin/ "/data/httpd/cgi-bin/"
# "/data/httpd/cgi-bin" should be changed to whatever your ScriptAliased
<Directory "/data/httpd/cgi-bin">
[root@mirror-centos8-p11 ~]# sed -ri "s@/data/httpd/htdocs@/data/httpd/www@g" /etc/httpd/httpd.conf
[root@mirror-centos8-p11 ~]# cat /etc/httpd/httpd.conf | grep "/data/httpd"
ServerRoot "/data/httpd"
DocumentRoot "/data/httpd/www"
<Directory "/data/httpd/www">
    ScriptAlias /cgi-bin/ "/data/httpd/cgi-bin/"
# "/data/httpd/cgi-bin" should be changed to whatever your ScriptAliased
<Directory "/data/httpd/cgi-bin">
[root@mirror-centos8-p11 ~]# 

  在 /data/httpd/www 下创建文件 index.html 用于验证目录切换,重启apache 服务

[root@mirror-centos8-p11 ~]# echo "This is `hostname -I`" > /data/httpd/www/index.html 
[root@mirror-centos8-p11 ~]# apachectl restart
[root@mirror-centos8-p11 ~]#

 

 

  创建目录  /data/httpd/www/mirror/centos/8/x86_64

oot@mirror-centos8-p11 ~]# mkdir -p /data/httpd/www/mirror/centos/8/x86_64
[root@mirror-centos8-p11 ~]# 

  前期准备。配置zabbix网络源

[root@mirror-centos8-p11 x86_64]# yum repolist
repo id                                                                repo name
AppStream                                                              AppStream
BaseOS                                                                 BaseOS
zabbix                                                                 zabbix
[root@mirror-centos8-p11 x86_64]# cat /etc/yum.repos.d/zabbix.repo 
[zabbix]
name=zabbix
baseurl=https://repo.zabbix.com/zabbix/4.0/rhel/8/x86_64/
gpgcheck=1
gpgkey=https://repo.zabbix.com/zabbix-official-repo.key
enabled=1
[root@mirror-centos8-p11 x86_64]# 

  使用dnf命令将zabbix下的源仓库下载至本地目录  /data/httpd/www/mirror/centos/8/x86_64

 

[root@mirror-centos8-p11 x86_64]# dnf reposync --repoid=zabbix --download-metadata -p /data/httpd/www/mirror/centos/8/x86_64
zabbix                                                                                                        936  B/s | 2.9 kB     00:03    
zabbix                                                                                                         33 kB/s | 788 kB     00:23    
(1/326): zabbix-agent-4.0.11-1.el8.x86_64.rpm                                                                  16 kB/s | 422 kB     00:27    
(2/326): zabbix-agent-4.0.11-2.el8.x86_64.rpm                                                                  15 kB/s | 423 kB     00:27    
(3/326): zabbix-agent-4.0.12-1.el8.x86_64.rpm                                                                  14 kB/s | 423 kB     00:30    
(4/326): zabbix-agent-4.0.14-1.el8.x86_64.rpm                                                                  14 kB/s | 425 kB     00:30    
(5/326): zabbix-agent-4.0.15-1.el8.x86_64.rpm                                                                  14 kB/s | 427 kB     00:31    
(6/326): zabbix-agent-4.0.13-1.el8.x86_64.rpm                                                                  11 kB/s | 424 kB     00:37    
(7/326): zabbix-agent-4.0.17-1.el8.x86_64.rpm                                                                  15 kB/s | 429 kB     00:28    
(8/326): zabbix-agent-4.0.16-1.el8.x86_64.rpm                                                                  12 kB/s | 428 kB     00:36    
(9/326): zabbix-agent-4.0.17-2.el8.x86_64.rpm                                                                  14 kB/s | 430 kB     00:30    
(10/326): zabbix-agent-4.0.19-1.el8.x86_64.rpm                                                                 14 kB/s | 434 kB     00:31    
(11/326): zabbix-agent-4.0.20-1.el8.x86_64.rpm                                                                 13 kB/s | 435 kB     00:33    
(12/326): zabbix-agent-4.0.21-1.el8.x86_64.rpm                                                                 20 kB/s | 436 kB     00:21    
(13/326): zabbix-agent-4.0.18-1.el8.x86_64.rpm                                                                7.0 kB/s | 431 kB     01:01    
(14/326): zabbix-agent-4.0.21-2.el8.x86_64.rpm                                                                 12 kB/s | 436 kB     00:36    
(15/326): zabbix-agent-4.0.22-1.el8.x86_64.rpm                                                                 16 kB/s | 436 kB     00:26    
(16/326): zabbix-agent-4.0.24-1.el8.x86_64.rpm                                                                 13 kB/s | 437 kB     00:33    
(17/326): zabbix-agent-4.0.23-1.el8.x86_64.rpm                                                                9.3 kB/s | 436 kB     00:47    
(18/326): zabbix-agent-4.0.25-1.el8.x86_64.rpm                                                                 17 kB/s | 438 kB     00:26    
(19/326): zabbix-agent-4.0.28-1.el8.x86_64.rpm                                                                 13 kB/s | 439 kB     00:32    
(20/326): zabbix-agent-4.0.26-1.el8.x86_64.rpm                                                                 12 kB/s | 438 kB     00:37    
(21/326): zabbix-agent-4.0.27-1.el8.x86_64.rpm                                                                9.1 kB/s | 438 kB     00:48    
(22/326): zabbix-agent-4.0.29-1.el8.x86_64.rpm                                                                8.0 kB/s | 439 kB     00:54    
(23/326): zabbix-agent-4.0.30-1.el8.x86_64.rpm                                                                7.2 kB/s | 440 kB     01:01    
(24/326): zabbix-agent-4.0.31-1.el8.x86_64.rpm                                                                7.2 kB/s | 444 kB     01:01    
(25/326): zabbix-agent-4.0.32-1.el8.x86_64.rpm                                                                 18 kB/s | 444 kB     00:25    
(26/326): zabbix-get-4.0.11-1.el8.x86_64.rpm                                                                   14 kB/s | 292 kB     00:21

......
 
(313/326): zabbix-web-pgsql-4.0.20-1.el8.noarch.rpm 119 kB/s | 14 kB 00:00
(314/326): zabbix-web-pgsql-4.0.21-1.el8.noarch.rpm 123 kB/s | 14 kB 00:00
(315/326): zabbix-web-pgsql-4.0.21-2.el8.noarch.rpm 124 kB/s | 14 kB 00:00
(316/326): zabbix-web-pgsql-4.0.22-1.el8.noarch.rpm 124 kB/s | 14 kB 00:00
(317/326): zabbix-web-pgsql-4.0.23-1.el8.noarch.rpm 113 kB/s | 14 kB 00:00
(318/326): zabbix-web-pgsql-4.0.24-1.el8.noarch.rpm 120 kB/s | 14 kB 00:00
(319/326): zabbix-web-pgsql-4.0.25-1.el8.noarch.rpm 128 kB/s | 15 kB 00:00
(320/326): zabbix-web-pgsql-4.0.26-1.el8.noarch.rpm 127 kB/s | 15 kB 00:00
(321/326): zabbix-web-pgsql-4.0.27-1.el8.noarch.rpm 132 kB/s | 15 kB 00:00
(322/326): zabbix-web-pgsql-4.0.28-1.el8.noarch.rpm 121 kB/s | 15 kB 00:00
(323/326): zabbix-web-pgsql-4.0.29-1.el8.noarch.rpm 122 kB/s | 15 kB 00:00
(324/326): zabbix-web-pgsql-4.0.30-1.el8.noarch.rpm 126 kB/s | 15 kB 00:00
(325/326): zabbix-web-pgsql-4.0.31-1.el8.noarch.rpm 138 kB/s | 15 kB 00:00
(326/326): zabbix-web-pgsql-4.0.32-1.el8.noarch.rpm 71 kB/s | 15 kB 00:00
[root@mirror-centos8-p11 x86_64]#

 

 

 

 

 

 本地源镜像

  将本地光盘挂载至 /mnt

[root@mirror-centos8-p11 ~]# mount /dev/sr0 /mnt
mount: /mnt: WARNING: device write-protected, mounted read-only.
[root@mirror-centos8-p11 ~]# ls /mnt
AppStream  BaseOS  EFI  images  isolinux  LICENSE  media.repo  TRANS.TBL
[root@mirror-centos8-p11 ~]# 

  将 AppStream BaseOS 拷贝至 /data/httpd/www//mirror/centos/8/x86_64

[root@mirror-centos8-p11 ~]# cp -r /mnt/AppStream /data/httpd/www/mirror/centos/8/x86_64/
[root@mirror-centos8-p11 ~]# cp -r /mnt/BaseOS /data/httpd/www/mirror/centos/8/x86_64/
[root@mirror-centos8-p11 ~]# ls /data/httpd/www/mirror/centos/8/x86_64/
AppStream  BaseOS  zabbix

 

 

 客户端验证

 清理原有yum源配置

[root@CentOS8 ~]# mkdir /etc/yum.repos.d/repo.bak
[root@CentOS8 ~]# mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repo.bak

新建yum配置,将地址指向内网仓库 10.0.0.11

[root@CentOS8 ~]# vim /etc/yum.repos.d/yumlist.repo

[BaseOS]
name=BaseOS
baseurl=http://10.0.0.11/mirror/centos/$releasever/$basearch/BaseOS
gpgcheck=0
enabled=1

[AppStream]
name=AppStream
baseurl=http://10.0.0.11/mirror/centos/$releasever/$basearch/AppStream
gpgcheck=0
enabled=1

[zabbix4.0]
name=Zabbix4.0
baseurl=http://10.0.0.11/mirror/centos/$releasever/$basearch/zabbix
gpgcheck=0
enabled=1

进行验证

[root@CentOS8 ~]# yum makecache 
BaseOS                                                                                                         21 MB/s | 2.5 MB     00:00    
AppStream                                                                                                      45 MB/s | 7.1 MB     00:00    
Zabbix4.0                                                                                                      22 MB/s | 211 kB     00:00    
Metadata cache created.

尝试安装zabbix-agent

[root@CentOS8 ~]# yum install zabbix-agent.x86_64 -y
Last metadata expiration check: 0:03:26 ago on Mon 09 Aug 2021 12:18:35 AM CST.
Dependencies resolved.
==============================================================================================================================================
 Package                             Architecture                  Version                             Repository                        Size
==============================================================================================================================================
Installing:
 zabbix-agent                        x86_64                        4.0.32-1.el8                        zabbix4.0                        444 k

Transaction Summary
==============================================================================================================================================
Install  1 Package

Total download size: 444 k
Installed size: 1.9 M
Downloading Packages:
zabbix-agent-4.0.32-1.el8.x86_64.rpm                                                                           30 MB/s | 444 kB     00:00    
----------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                          27 MB/s | 444 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                      1/1 
  Running scriptlet: zabbix-agent-4.0.32-1.el8.x86_64                                                                                     1/1 
  Installing       : zabbix-agent-4.0.32-1.el8.x86_64                                                                                     1/1 
  Running scriptlet: zabbix-agent-4.0.32-1.el8.x86_64                                                                                     1/1 
  Verifying        : zabbix-agent-4.0.32-1.el8.x86_64                                                                                     1/1 

Installed:
  zabbix-agent-4.0.32-1.el8.x86_64                                                                                                            

Complete!
[root@CentOS8 ~]# 

验证完成,自建内网仓库可用

 

sed文本处理

3、利用sed 取出ifconfig命令中本机的IPv4地址

[root@CentOS8 ~]# ifconfig ens160
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.0.8  netmask 255.255.255.0  broadcast 10.0.0.255
        inet6 fe80::20c:29ff:fee1:7a9e  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:e1:7a:9e  txqueuelen 1000  (Ethernet)
        RX packets 1220  bytes 152403 (148.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 979  bytes 105624 (103.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@CentOS8 ~]# ifconfig ens160 | sed -rn "s/.*inet ([0-9].*)\snetmask.*/\1/p"
10.0.0.8 
[root@CentOS8 ~]# 

 

4、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符

[root@CentOS8 ~]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Mon Jul 12 15:41:50 2021
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/cl-root     /                       xfs     defaults        0 0
UUID=171bcdb1-4ccb-46fd-85ea-0f028cd5fe36 /boot                   xfs     defaults        0 0
/dev/mapper/cl-data     /data                   xfs     defaults        0 0
/dev/mapper/cl-swap     none                    swap    defaults        0 0

[root@CentOS8 ~]# sed -r "s/^#[[:space:]]+(.*)/\1/p" /etc/fstab 

#
/etc/fstab
/etc/fstab
Created by anaconda on Mon Jul 12 15:41:50 2021
Created by anaconda on Mon Jul 12 15:41:50 2021
#
Accessible filesystems, by reference, are maintained under '/dev/disk/'.
Accessible filesystems, by reference, are maintained under '/dev/disk/'.
See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
After editing this file, run 'systemctl daemon-reload' to update systemd
After editing this file, run 'systemctl daemon-reload' to update systemd
units generated from this file.
units generated from this file.
#
/dev/mapper/cl-root     /                       xfs     defaults        0 0
UUID=171bcdb1-4ccb-46fd-85ea-0f028cd5fe36 /boot                   xfs     defaults        0 0
/dev/mapper/cl-data     /data                   xfs     defaults        0 0
/dev/mapper/cl-swap     none                    swap    defaults        0 0
[root@CentOS8 ~]# 

 

5、处理/etc/fstab路径,使用sed命令取出其目录名和基名

[root@CentOS8 ~]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Mon Jul 12 15:41:50 2021
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/cl-root     /                       xfs     defaults        0 0
UUID=171bcdb1-4ccb-46fd-85ea-0f028cd5fe36 /boot                   xfs     defaults        0 0
/dev/mapper/cl-data     /data                   xfs     defaults        0 0
/dev/mapper/cl-swap     none                    swap    defaults        0 0

[root@CentOS8 ~]# sed -rn "/^[^#|$]/s/^(\S+)\s*(\S+).*/\1   \2/p" /etc/fstab
/dev/mapper/cl-root   /
UUID=171bcdb1-4ccb-46fd-85ea-0f028cd5fe36   /boot
/dev/mapper/cl-data   /data
/dev/mapper/cl-swap   none
[root@CentOS8 ~]# 

 

6、列出ubuntu软件管理工具apt的一些用法(自由总结)

 

apt 语法

  apt [options] [command] [package ...]
  • options:可选,选项包括 -h(帮助),-y(当安装过程提示选择全部为"yes"),-q(不显示安装的过程)等等。
  • command:要进行的操作。
  • package:安装的包名。

apt 常用命令

  • 列出所有可更新的软件清单命令:sudo apt update

  • 升级软件包:sudo apt upgrade

    列出可更新的软件包及版本信息:apt list --upgradeable

    升级软件包,升级前先删除需要更新软件包:sudo apt full-upgrade

  • 安装指定的软件命令:sudo apt install <package_name>

    安装多个软件包:sudo apt install <package_1> <package_2> <package_3>

  • 更新指定的软件命令:sudo apt update <package_name>

  • 显示软件包具体信息,例如:版本号,安装大小,依赖关系等等:sudo apt show <package_name>

  • 删除软件包命令:sudo apt remove <package_name>

  • 清理不再使用的依赖和库文件: sudo apt autoremove

  • 移除软件包及配置文件: sudo apt purge <package_name>

  • 查找软件包命令: sudo apt search <keyword>

  • 列出所有已安装的包:apt list --installed

  • 列出所有已安装的包的版本信息:apt list --all-versions



这篇关于【Linux】sed文本处理及软件管理的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程