IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> 使用grep&sed快速更换Ubuntu为国内镜像源 -> 正文阅读

[系统运维]使用grep&sed快速更换Ubuntu为国内镜像源

1、、原理分析grep&sed查找指定字符串并替换
命令行:sed -i "s/SAXON_BLE/OWENS_BLE/g" `grep -rl "SAXON_BLE" ./`

分析:sed:字符串替换命令

? ? ? ? ? ?-i:表示当前替换

? ? ? ? ? ?"s/SAXON_BLE/OWENS_BLE/g":s/old_string/new_string/g

? ? ? ? ? ?grep:字符串查找命令,功能很强大

? ? ? ? ? ?-r:recursive,递归

? ? ? ? ? ?-l:返回文件名

? ? ? ? ? ? "SAXON_BLE":需要查找的字符串

? ? ? ? ? ? ./:查找路径,表示当前路径

2,先将源列表文件sources.list备份

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

3、查看sources.list文件,确认需要将archive.ubuntu.com和security.ubuntu.com替换为国内源

ubuntu@docker:~$ cat /etc/apt/sources.list
## Note, this file is written by cloud-init on first boot of an instance
## modifications made here will not survive a re-bundle.
## if you wish to make changes you can:
## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg
##     or do the same in user-data
## b.) add sources in /etc/apt/sources.list.d
## c.) make changes to template file /etc/cloud/templates/sources.list.tmpl

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://archive.ubuntu.com/ubuntu impish main restricted
# deb-src http://archive.ubuntu.com/ubuntu impish main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://archive.ubuntu.com/ubuntu impish-updates main restricted
# deb-src http://archive.ubuntu.com/ubuntu impish-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://archive.ubuntu.com/ubuntu impish universe
# deb-src http://archive.ubuntu.com/ubuntu impish universe
deb http://archive.ubuntu.com/ubuntu impish-updates universe
# deb-src http://archive.ubuntu.com/ubuntu impish-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://archive.ubuntu.com/ubuntu impish multiverse
# deb-src http://archive.ubuntu.com/ubuntu impish multiverse
deb http://archive.ubuntu.com/ubuntu impish-updates multiverse
# deb-src http://archive.ubuntu.com/ubuntu impish-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://archive.ubuntu.com/ubuntu impish-backports main restricted universe multiverse
# deb-src http://archive.ubuntu.com/ubuntu impish-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu impish partner
# deb-src http://archive.canonical.com/ubuntu impish partner

deb http://security.ubuntu.com/ubuntu impish-security main restricted
# deb-src http://security.ubuntu.com/ubuntu impish-security main restricted
deb http://security.ubuntu.com/ubuntu impish-security universe
# deb-src http://security.ubuntu.com/ubuntu impish-security universe
deb http://security.ubuntu.com/ubuntu impish-security multiverse
# deb-src http://security.ubuntu.com/ubuntu impish-security multiverse

?4、执行替换,并检查替换情况

ubuntu@docker:~$ sudo sed -i "s/archive.ubuntu.com/mirrors.163.com/g" `grep -rl "archive.ubuntu.com" /etc/apt/sources.list`

ubuntu@docker:~$ sudo sed -i "s/security.ubuntu.com/mirrors.163.com/g" `grep -rl "security.ubuntu.com" /etc/apt/sources.list`

ubuntu@docker:~$ cat /etc/apt/sources.list
## Note, this file is written by cloud-init on first boot of an instance
## modifications made here will not survive a re-bundle.
## if you wish to make changes you can:
## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg
##     or do the same in user-data
## b.) add sources in /etc/apt/sources.list.d
## c.) make changes to template file /etc/cloud/templates/sources.list.tmpl

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://mirrors.163.com/ubuntu impish main restricted
# deb-src http://mirrors.163.com/ubuntu impish main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://mirrors.163.com/ubuntu impish-updates main restricted
# deb-src http://mirrors.163.com/ubuntu impish-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://mirrors.163.com/ubuntu impish universe
# deb-src http://mirrors.163.com/ubuntu impish universe
deb http://mirrors.163.com/ubuntu impish-updates universe
# deb-src http://mirrors.163.com/ubuntu impish-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://mirrors.163.com/ubuntu impish multiverse
# deb-src http://mirrors.163.com/ubuntu impish multiverse
deb http://mirrors.163.com/ubuntu impish-updates multiverse
# deb-src http://mirrors.163.com/ubuntu impish-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://mirrors.163.com/ubuntu impish-backports main restricted universe multiverse
# deb-src http://mirrors.163.com/ubuntu impish-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu impish partner
# deb-src http://archive.canonical.com/ubuntu impish partner

deb http://mirrors.163.com/ubuntu impish-security main restricted
# deb-src http://mirrors.163.com/ubuntu impish-security main restricted
deb http://mirrors.163.com/ubuntu impish-security universe
# deb-src http://mirrors.163.com/ubuntu impish-security universe
deb http://mirrors.163.com/ubuntu impish-security multiverse
# deb-src http://mirrors.163.com/ubuntu impish-security multiverse

5、更新

sudo apt-get update #更新软件列表
sudo apt-get upgrade # 更新本地软件

?

  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2022-07-04 23:22:23  更:2022-07-04 23:22:46 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/18 18:36:00-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码