Linux学习--yum仓库apt仓库和sed命令练习
Posted 泡沫之曦
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
AppStream BaseOS EFI images isolinux media.repo TRANS.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的一些用法(自由总结)
apt install [软件] 安装软件
remove 卸载软件(不删除配置文件)
purge 卸载软件并删除配置文件
update 更新apt缓存以及索引信息
list 列出已安装和未安装的deb包
apt-file 查找不存在的文件在那个包(apt-file是一个工具需要安装)
apt-file search -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 / xfs defaults 0 0
UUID=3e3f300f-6931-449e-bdfa-1bdfbdca51ba /boot ext4 defaults 1 2
UUID=07f27e96-94fe-4e44-9ef2-03a8ffceb787 /date xfs defaults 0 0
UUID=561fb218-ee0c-4046-b97f-3786ad3d7200 swap swap defaults 0 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 / xfs defaults 0 0
UUID=3e3f300f-6931-449e-bdfa-1bdfbdca51ba /boot ext4 defaults 1 2
UUID=07f27e96-94fe-4e44-9ef2-03a8ffceb787 /date xfs defaults 0 0
UUID=561fb218-ee0c-4046-b97f-3786ad3d7200 swap swap defaults 0 0
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
以上是关于Linux学习--yum仓库apt仓库和sed命令练习的主要内容,如果未能解决你的问题,请参考以下文章
自建yum仓库;编译安装http2.4 ;删除/etc/fstab文件中所有以#开头的行;sed 取本机的IP地址;sed命令取目录名