Linux学习--yum仓库apt仓库和sed命令练习

万事须己运,他得非我贤。这篇文章主要讲述Linux学习--yum仓库apt仓库和sed命令练习相关的知识,希望能为你提供帮助。
1、自建yum仓库,分别为网络源和本地源
网络源:

[root@centos8 ~]$vim /etc/yum.repos.d/yum.repo
[app]
name=app
baseurl=https://mirrors.aliyun.com/centos/$releasever/AppStream/$basearch/os/
https://mirrors.cloud.tencent.com/centos/$releasever/AppStream/$basearch/os/
https://repo.huaweicloud.com/centos/$releasever/AppStream/$basearch/os/
https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/AppStream/$basearch/os/
enabled=1
gpgcheck=1
gpgkey=file:////etc/pki/rpm-gpg/RPM-GPG-KEY-centostesting

[base]
name=base
baseurl=https://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
https://mirrors.cloud.tencent.com/centos/$releasever/BaseOS/$basearch/os/
https://repo.huaweicloud.com/centos/$releasever/BaseOS/$basearch/os/
https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/BaseOS/$basearch/os/
enabled=1

[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/$releasever/Everything/$basearch/

本地源:
[root@centos8 cdrom]$yum -y install autofs
[root@centos8 ~]$systemctl start autofs.service
[root@centos8 ~]$systemctl enable autofs.service
Created symlink /etc/systemd/system/multi-user.target.wants/autofs.service → /usr/lib/systemd/system/autofs.service.
[root@centos8 misc]$cd /misc/cd
[root@centos8 cd]$ls
AppStreamBaseOSEFIimagesisolinuxmedia.repoTRANS.TBL
[root@centos8 ~]$vim /etc/yum.repos.d/yum1.repo
[app]
name=app
baseurl=file:////mnt/cdrom/AppStream/Packages
enabled=1
gpgcheck=1
gpgkey=file:////etc/pki/rpm-gpg/RPM-GPG-KEY-centostesting

[base]
name=base
baseurl=file:////mnt/cdrom/BaseOS/Packages
enabled=1

2.自建apt仓库
sed -i s/hk.archive.ubuntu.com/mirrors.aliyun.com/ /etc/apt/sources.list
sed -i s/security.ubuntu.com/mirrors.aliyun.com/ /etc/apt/sources.list

3.列出ubuntu软件管理工具apt的一些用法(自由总结)
aptinstall[软件]安装软件
remove卸载软件(不删除配置文件)
purge卸载软件并删除配置文件
update更新apt缓存以及索引信息
list列出已安装和未安装的deb包
apt-file查找不存在的文件在那个包(apt-file是一个工具需要安装)
apt-filesearch-x可以使用正则表达式查询
stats统计系统安装包的信息
show查看包的详细信息
apt-cache madison查看仓库中的指定软件的所有版本

4.利用sed 取出ifconfig命令中本机的IPv4地址
[root@centos8 ~]$ifconfig eth0 | sed -nr "2s/[^0-9]+([0-9.]+).*/\\1/p"
192.168.150.101

5.删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
[root@centos8 ~]$cp /etc/fstab /date/
[root@centos8 ~]$cat /date/fstab

#
# /etc/fstab
# Created by anaconda on Mon Nov 15 09:47:11 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.
#
UUID=ef62226a-1745-494a-9cb0-29dfb51865df /xfsdefaults0 0
UUID=3e3f300f-6931-449e-bdfa-1bdfbdca51ba /bootext4defaults1 2
UUID=07f27e96-94fe-4e44-9ef2-03a8ffceb787 /datexfsdefaults0 0
UUID=561fb218-ee0c-4046-b97f-3786ad3d7200 swapswapdefaults0 0
[root@centos8 ~]$sed -ri "/^#[ \\+]/s///" /date/fstab
[root@centos8 ~]$cat /date/fstab

#
/etc/fstab
Created by anaconda on Mon Nov 15 09:47:11 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.
#
UUID=ef62226a-1745-494a-9cb0-29dfb51865df /xfsdefaults0 0
UUID=3e3f300f-6931-449e-bdfa-1bdfbdca51ba /bootext4defaults1 2
UUID=07f27e96-94fe-4e44-9ef2-03a8ffceb787 /datexfsdefaults0 0
UUID=561fb218-ee0c-4046-b97f-3786ad3d7200 swapswapdefaults0 0

【Linux学习--yum仓库apt仓库和sed命令练习】6.处理/etc/fstab路径,使用sed命令取出其目录名和基名
[root@centos8 ~]$echo "/etc/fstab" |sed -rn s#(.*)/([^/]+)/?#\\1#p
/etc
[root@centos8 ~]$echo "/etc/fstab" |sed -rn s#(.*)/([^/]+)/?#\\2#p
fstab


    推荐阅读