• 使用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替换为国内源

    1. ubuntu@docker:~$ cat /etc/apt/sources.list
    2. ## Note, this file is written by cloud-init on first boot of an instance
    3. ## modifications made here will not survive a re-bundle.
    4. ## if you wish to make changes you can:
    5. ## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg
    6. ## or do the same in user-data
    7. ## b.) add sources in /etc/apt/sources.list.d
    8. ## c.) make changes to template file /etc/cloud/templates/sources.list.tmpl
    9. # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
    10. # newer versions of the distribution.
    11. deb http://archive.ubuntu.com/ubuntu impish main restricted
    12. # deb-src http://archive.ubuntu.com/ubuntu impish main restricted
    13. ## Major bug fix updates produced after the final release of the
    14. ## distribution.
    15. deb http://archive.ubuntu.com/ubuntu impish-updates main restricted
    16. # deb-src http://archive.ubuntu.com/ubuntu impish-updates main restricted
    17. ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
    18. ## team. Also, please note that software in universe WILL NOT receive any
    19. ## review or updates from the Ubuntu security team.
    20. deb http://archive.ubuntu.com/ubuntu impish universe
    21. # deb-src http://archive.ubuntu.com/ubuntu impish universe
    22. deb http://archive.ubuntu.com/ubuntu impish-updates universe
    23. # deb-src http://archive.ubuntu.com/ubuntu impish-updates universe
    24. ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
    25. ## team, and may not be under a free licence. Please satisfy yourself as to
    26. ## your rights to use the software. Also, please note that software in
    27. ## multiverse WILL NOT receive any review or updates from the Ubuntu
    28. ## security team.
    29. deb http://archive.ubuntu.com/ubuntu impish multiverse
    30. # deb-src http://archive.ubuntu.com/ubuntu impish multiverse
    31. deb http://archive.ubuntu.com/ubuntu impish-updates multiverse
    32. # deb-src http://archive.ubuntu.com/ubuntu impish-updates multiverse
    33. ## N.B. software from this repository may not have been tested as
    34. ## extensively as that contained in the main release, although it includes
    35. ## newer versions of some applications which may provide useful features.
    36. ## Also, please note that software in backports WILL NOT receive any review
    37. ## or updates from the Ubuntu security team.
    38. deb http://archive.ubuntu.com/ubuntu impish-backports main restricted universe multiverse
    39. # deb-src http://archive.ubuntu.com/ubuntu impish-backports main restricted universe multiverse
    40. ## Uncomment the following two lines to add software from Canonical's
    41. ## 'partner' repository.
    42. ## This software is not part of Ubuntu, but is offered by Canonical and the
    43. ## respective vendors as a service to Ubuntu users.
    44. # deb http://archive.canonical.com/ubuntu impish partner
    45. # deb-src http://archive.canonical.com/ubuntu impish partner
    46. deb http://security.ubuntu.com/ubuntu impish-security main restricted
    47. # deb-src http://security.ubuntu.com/ubuntu impish-security main restricted
    48. deb http://security.ubuntu.com/ubuntu impish-security universe
    49. # deb-src http://security.ubuntu.com/ubuntu impish-security universe
    50. deb http://security.ubuntu.com/ubuntu impish-security multiverse
    51. # deb-src http://security.ubuntu.com/ubuntu impish-security multiverse

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

    1. ubuntu@docker:~$ sudo sed -i "s/archive.ubuntu.com/mirrors.163.com/g" `grep -rl "archive.ubuntu.com" /etc/apt/sources.list`
    2. ubuntu@docker:~$ sudo sed -i "s/security.ubuntu.com/mirrors.163.com/g" `grep -rl "security.ubuntu.com" /etc/apt/sources.list`
    3. ubuntu@docker:~$ cat /etc/apt/sources.list
    4. ## Note, this file is written by cloud-init on first boot of an instance
    5. ## modifications made here will not survive a re-bundle.
    6. ## if you wish to make changes you can:
    7. ## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg
    8. ## or do the same in user-data
    9. ## b.) add sources in /etc/apt/sources.list.d
    10. ## c.) make changes to template file /etc/cloud/templates/sources.list.tmpl
    11. # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
    12. # newer versions of the distribution.
    13. deb http://mirrors.163.com/ubuntu impish main restricted
    14. # deb-src http://mirrors.163.com/ubuntu impish main restricted
    15. ## Major bug fix updates produced after the final release of the
    16. ## distribution.
    17. deb http://mirrors.163.com/ubuntu impish-updates main restricted
    18. # deb-src http://mirrors.163.com/ubuntu impish-updates main restricted
    19. ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
    20. ## team. Also, please note that software in universe WILL NOT receive any
    21. ## review or updates from the Ubuntu security team.
    22. deb http://mirrors.163.com/ubuntu impish universe
    23. # deb-src http://mirrors.163.com/ubuntu impish universe
    24. deb http://mirrors.163.com/ubuntu impish-updates universe
    25. # deb-src http://mirrors.163.com/ubuntu impish-updates universe
    26. ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
    27. ## team, and may not be under a free licence. Please satisfy yourself as to
    28. ## your rights to use the software. Also, please note that software in
    29. ## multiverse WILL NOT receive any review or updates from the Ubuntu
    30. ## security team.
    31. deb http://mirrors.163.com/ubuntu impish multiverse
    32. # deb-src http://mirrors.163.com/ubuntu impish multiverse
    33. deb http://mirrors.163.com/ubuntu impish-updates multiverse
    34. # deb-src http://mirrors.163.com/ubuntu impish-updates multiverse
    35. ## N.B. software from this repository may not have been tested as
    36. ## extensively as that contained in the main release, although it includes
    37. ## newer versions of some applications which may provide useful features.
    38. ## Also, please note that software in backports WILL NOT receive any review
    39. ## or updates from the Ubuntu security team.
    40. deb http://mirrors.163.com/ubuntu impish-backports main restricted universe multiverse
    41. # deb-src http://mirrors.163.com/ubuntu impish-backports main restricted universe multiverse
    42. ## Uncomment the following two lines to add software from Canonical's
    43. ## 'partner' repository.
    44. ## This software is not part of Ubuntu, but is offered by Canonical and the
    45. ## respective vendors as a service to Ubuntu users.
    46. # deb http://archive.canonical.com/ubuntu impish partner
    47. # deb-src http://archive.canonical.com/ubuntu impish partner
    48. deb http://mirrors.163.com/ubuntu impish-security main restricted
    49. # deb-src http://mirrors.163.com/ubuntu impish-security main restricted
    50. deb http://mirrors.163.com/ubuntu impish-security universe
    51. # deb-src http://mirrors.163.com/ubuntu impish-security universe
    52. deb http://mirrors.163.com/ubuntu impish-security multiverse
    53. # deb-src http://mirrors.163.com/ubuntu impish-security multiverse

    5、更新

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

     

  • 相关阅读:
    MMDeploy部署实战系列【第五章】:Windows下Release x64编译mmdeploy c++SDK,对TensorRT模型进行推理
    git忽略提交文件
    Day32力扣打卡
    IDEA快捷键
    c++匿名对象
    Kotlin协程:flowOn与线程切换
    泛微OA建模查询中自定义按钮弹出自定义对话框+调用新建表单卡片中的保存功能
    卷积神经网络提取的图像特征包括哪些
    列表的增删改查和遍历
    MachineLearning 13. 机器学习之降维方法UMAP及可视化 (umap)
  • 原文地址:https://blog.csdn.net/skayliu/article/details/125549568