8.10-8.13 笔记

知识点 shell基础知识

cut,sort,wc,uniq,tee,tr,split


cut分割

选项

  • -d 指定字段的分隔符,默认的字段分隔符为“TAB”
  • -f 指定段号
  • -c 指定第几个字符
[root@localhost test]#cat passwd.txt | head -5 |cut -d: -f1-6   //用的比较多
root:x:0:0:root:/root
bin:x:1:1:bin:/bin
daemon:x:2:2:daemon:/sbin
adm:x:3:4:adm:/var/adm
lp:x:4:7:lp:/var/spool/lpd
[root@localhost test]#cat passwd.txt | head -5 |cut -c 4   
t
:
m
:
x

sort排序

选项

  • n 按数字排序
  • r 反序
  • t 分隔符
  • k 第几段
[root@localhost test]#sort -n passwd.txt //正序排列


adm:x:3:4:adm:/var/adm:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
chrony:x:998:996::/var/lib/chrony:/sbin/nologin
chrony:x:998:996::/var/lib/chrony:/sbin/nologin
chrony:x:998:996::/var/lib/chrony:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
[root@localhost test]#sort -r passwd.txt  //反序排列
www:x:1000:1000::/home/www:/bin/bash
www:x:1000:1000::/home/www:/bin/bash
www:x:1000:1000::/home/www:/bin/bash
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin

wc

选项

  • l 统计行数
  • m 统计字符数
  • w 统计词
  • L 和m差不多,不过不计算最后的换行符$
[root@localhost test]#wc -l < passwd.txt 
93
[root@localhost test]#wc -m < passwd.txt 
2941
[root@localhost test]#wc -w < passwd.txt 
134
[root@localhost test]#wc -L < passwd.txt 
68

uniq去重

去重命令,不过不是很智能,需要配合sort一起使用

[root@localhost test]#cat tt.txt 
aaa
bbb
ccc
ddd
abc
aaa
adc
ddd
bbb
bac

[root@localhost test]#uniq tt.txt 
aaa
bbb
ccc
ddd
abc
aaa
adc
ddd
bbb
bac

[root@localhost test]#sort tt.txt | uniq

aaa
abc
adc
bac
bbb
ccc
ddd
[root@localhost test]#sort tt.txt | uniq -c  //统计相同的行有多少行
      1 
      2 aaa
      1 abc
      1 adc
      1 bac
      2 bbb
      1 ccc
      2 ddd
[root@localhost test]#chattr +i tt.txt 
[root@localhost test]#lsattr tt.txt    //不会更改源文件属性!
----i----------- tt.txt
[root@localhost test]#sort tt.txt | uniq -c
      1 
      2 aaa
      1 abc
      1 adc
      1 bac
      2 bbb
      1 ccc
      2 ddd

tee重定向并显示

>的同时并显示到屏幕上,将前面的结果通过 ‘| tee ’输出给后面的文件并且输出在屏幕上。

[root@localhost test]#more middle.txt | tee more.txt
cat: hello: 没有那个文件或目录
cat: hello: 没有那个文件或目录
[root@localhost test]#ls
11.txt    hello.txt   more.txt    semanage.conf  tt.txt  wwww.txt
copy.txt  middle.txt  passwd.txt  test.zip       www     xxoo
[root@localhost test]#cat more.txt 
cat: hello: 没有那个文件或目录
cat: hello: 没有那个文件或目录

tr替换字符

  • d 表示删除某个字符,后面跟要删除的字符
  • s 表示删除重复的字符
[root@localhost test]#cat more.txt 
cat: hello: 没有那个文件或目录
cat: hello: 没有那个文件或目录
[root@localhost test]#cat more.txt | tr 'cat' 'dog'
dog: hello: 没有那个文件或目录
dog: hello: 没有那个文件或目录
[root@localhost test]#cat more.txt | tr '[a-z]' '[A-Z]'
CAT: HELLO: 没有那个文件或目录
CAT: HELLO: 没有那个文件或目录
[root@localhost test]#cat more.txt | tr -d ca
t: hello: 没有那个文件或目录
t: hello: 没有那个文件或目录

split切割

选项

  • b 按照大小来分割,默认单位是byte
  • l 按照行数来分割
[root@localhost test]#ll xxoo
-rw-r--r--. 1 root root 2321 10月 31 16:49 xxoo
[root@localhost test]#split -b 1000 xxoo 
[root@localhost test]#ll
-rw-r--r--. 1 root root 1000 11月 11 17:01 xaa
-rw-r--r--. 1 root root 1000 11月 11 17:01 xab
-rw-r--r--. 1 root root  321 11月 11 17:01 xac
-rw-r--r--. 1 root root 2321 10月 31 16:49 xxoo
[root@localhost test]#du -sh xaa
4.0K	xaa
[root@localhost test]#du -sh xab
4.0K	xab
[root@localhost test]#du -sh xac
4.0K	xac
[root@localhost test]#split -l 20 xxoo 
-rw-r--r--. 1 root root  926 11月 11 17:04 xaa   //把老的切割文件给覆盖了!
-rw-r--r--. 1 root root  949 11月 11 17:04 xab
-rw-r--r--. 1 root root  446 11月 11 17:04 xac
-rw-r--r--. 1 root root 2321 10月 31 16:49 xxoo
[root@localhost test]#vi xaa

      1  Authors: Jason Tang <jtang@tresys.com>
      2 #
      3 # Copyright (C) 2004-2005 Tresys Technology, LLC
      4 #
      5 #  This library is free software; you can redistribute it and/or
      6 #  modify it under the terms of the GNU Lesser General Public
      7 #  License as published by the Free Software Foundation; either
      8 #  version 2.1 of the License, or (at your option) any later version.
      9 #
     10 #  This library is distributed in the hope that it will be useful,
     11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13 #  Lesser General Public License for more details.
     14 #
     15 #  You should have received a copy of the GNU Lesser General Public
     16 #  License along with this library; if not, write to the Free Software
     17 #  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     18 #
     19 # Specify how libsemanage will interact with a SELinux policy manager.
     20 # The four options are:
~                                                                                                                 
~                                                                                                                 
:set nu
[root@localhost test]#split -l 50 xxoo cat  //文件名指定以cat开头,这样就不会覆盖了!
[root@localhost test]#ll
-rw-r--r--. 1 root root 2304 11月 11 17:09 cataa
-rw-r--r--. 1 root root   17 11月 11 17:09 catab
-rw-r--r--. 1 root root  926 11月 11 17:04 xaa
-rw-r--r--. 1 root root  949 11月 11 17:04 xab
-rw-r--r--. 1 root root  446 11月 11 17:04 xac
-rw-r--r--. 1 root root 2321 10月 31 16:49 xxoo


特殊符号

  • $ 用作变量前面的标识符,
  • ; 如果想在一行中间允许2个以上命令,可以使用该符号
  • ~ 用户的home目录
  • & 如果想把一条命令放到后台可以使用该符号
  • [] 上面讲过的[]中的值任取一个。
  • &&和|| 逻辑与和逻辑或
[root@localhost test]#mkdir /test/1/2 || ll
mkdir: 无法创建目录"/test/1/2": 没有那个文件或目录
-rw-r--r--. 1 root root  120 11月 11 10:28 11.txt
-rw-r--r--. 1 root root 2304 11月 11 17:09 cataa
-rw-r--r--. 1 root root   17 11月 11 17:09 catab
-rw-r--r--. 1 root root  926 11月 11 17:04 xaa
-rw-r--r--. 1 root root  949 11月 11 17:04 xab
-rw-r--r--. 1 root root  446 11月 11 17:04 xac
-rw-r--r--. 1 root root 2321 10月 31 16:49 xxoo
[root@localhost test]#mkdir /test/1/2 && ll
mkdir: 无法创建目录"/test/1/2": 没有那个文件或目录
[root@localhost test]#touch 12.txt
[root@localhost test]#touch 1.txt
[root@localhost test]#touch 2.txt
[root@localhost test]#ls [12].txt
1.txt  2.txt
[root@localhost test]#ls *.txt
11.txt  12.txt  1.txt  2.txt  copy.txt  hello.txt  middle.txt  more.txt  passwd.txt  tt.txt  wwww.txt

转载于:https://my.oschina.net/u/3997678/blog/2874697

【完美复现】面向配电网韧性提升的移动储能预布局与动态调度策略【IEEE33节点】(Matlab代码实现)内容概要:本文介绍了基于IEEE33节点的配电网韧性提升方法,重点研究了移动储能系统的预布局与动态调度策略。通过Matlab代码实现,提出了一种结合预配置和动态调度的两阶段优化模型,旨在应对电网故障或极端事件时快速恢复供电能力。文中采用了多种智能优化算法(如PSO、MPSO、TACPSO、SOA、GA等)进行对比分析,验证所提策略的有效性和优越性。研究不仅关注移动储能单元的初始部署位置,还深入探讨其在故障发生后的动态路径规划与电力支援过程,从而全面提升配电网的韧性水平。; 适合人群:具备电力系统基础知识和Matlab编程能力的研究生、科研人员及从事智能电网、能源系统优化等相关领域的工程技术人员。; 使用场景及目标:①用于科研复现,特别是IEEE顶刊或SCI一区论文中关于配电网韧性、应急电源调度的研究;②支撑电力系统在灾害或故障条件下的恢复力优化设计,提升实际电网应对突发事件的能力;③为移动储能系统在智能配电网中的应用提供理论依据和技术支持。; 阅读建议:建议读者结合提供的Matlab代码逐模块分析,重点关注目标函数建模、约束条件设置以及智能算法的实现细节。同时推荐参考文中提及的MPS预配置与动态调度上下两部分,系统掌握完整的技术路线,并可通过替换不同算法或测试系统进一步拓展研究。
<think>我们正在处理Anolis OS 8.10中yum仓库元数据下载失败的问题,具体报错是404,无法下载repomd.xml文件。 根据之前的解决方案,主要问题可能是仓库路径中的变量(如$releasever)被解析为不正确的值(如解析成8而不是8.10),导致路径错误。 因此,我们需要修改仓库配置文件,将$releasever替换为固定的版本号8.10,并确保使用正确的镜像源。 步骤: 1. 验证当前系统版本和架构。 2. 修改/etc/yum.repos.d/目录下的仓库配置文件(通常是anolis.repo),将$releasever替换为8.10。 3. 如果官方镜像源有问题,可以切换到阿里云镜像源。 4. 清除yum缓存并重新生成。 注意:用户已经尝试过步骤4,但报错404,所以我们需要修正仓库配置。 另外,根据引用,Anolis OS 8.10的仓库路径结构可能是以8.10为目录,而不是8。因此,使用固定版本号8.10是关键。 下面给出具体步骤:</think>### 解决 Anolis OS 8.10 仓库元数据下载失败问题(repomd.xml 404 错误) #### 🔍 问题分析 报错 `Status code: 404 for .../repodata/repomd.xml` 表明: 1. **路径不匹配**:`$releasever` 变量被错误解析为 `8` 而非 `8.10` 2. **镜像同步问题**:官方镜像站可能未及时同步或路径变更 3. **仓库配置错误**:默认配置未适配 8.10 的路径结构 --- #### 🛠 解决方案(逐步操作) ##### ✅ 步骤 1:验证系统信息 ```bash # 检查系统版本和架构 cat /etc/os-release | grep VERSION_ID uname -m # 确认是 x86_64 还是 aarch64 ``` ##### ✅ 步骤 2:修正仓库配置文件 编辑仓库配置文件: ```bash sudo vi /etc/yum.repos.d/anolis.repo ``` 修改为以下内容(**关键修改已标出**): ```ini [base] name=Anolis OS 8.10 - Base # 重点:显式使用 8.10 替代 $releasever baseurl=https://mirrors.openanolis.cn/anolis/8.10/BaseOS/$basearch/os/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ANOLIS [updates] name=Anolis OS 8.10 - Updates # 重点:路径必须包含 8.10 baseurl=https://mirrors.openanolis.cn/anolis/8.10/Updates/$basearch/os/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ANOLIS [extras] name=Anolis OS 8.10 - Extras baseurl=https://mirrors.openanolis.cn/anolis/8.10/Extras/$basearch/os/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ANOLIS ``` > **修改说明**: > - 将 `$releasever` 替换为固定值 `8.10`(解决变量解析错误) > - 确保路径包含完整版本号(`8.10` 而非 `8`) ##### ✅ 步骤 3:切换镜像源(如官方源失效) 若官方镜像仍不可用,改用阿里云镜像: ```bash sudo sed -i 's|https://mirrors.openanolis.cn|https://mirrors.aliyun.com/anolis|g' /etc/yum.repos.d/anolis.repo ``` ##### ✅ 步骤 4:强制刷新元数据 ```bash # 清除旧缓存 sudo yum clean all sudo rm -rf /var/cache/yum # 重建元数据 sudo yum makecache # 验证仓库状态 sudo yum repolist ``` --- #### ⚙️ 高级排查 若仍失败,手动测试仓库可达性: ```bash # 替换 x86_64 为您的架构(如 aarch64) MIRROR="https://mirrors.aliyun.com/anolis" curl -I "${MIRROR}/8.10/Updates/x86_64/os/repodata/repomd.xml" ``` 期望返回 **HTTP 200** 状态码 --- #### ✅ 成功验证标志 执行 `yum repolist` 应显示: ```bash 仓库标识 仓库名称 状态 base Anolis OS 8.10 - Base 10,219 updates Anolis OS 8.10 - Updates 1,847 extras Anolis OS 8.10 - Extras 586 ``` > **根本原因**: > Anolis OS 8.10 的 `$releasever` 变量被错误解析为 `8` 而非 `8.10`[^1],导致访问路径 `8/Updates/`(不存在)而非正确的 `8.10/Updates/`。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值