Linux Shell教程(二) 互动版

在线工具推荐: Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器

数据的搜寻并显示

范例1:搜索 /etc/passwd有root关键字的行。

$ nl /etc/passwd | sed '/root/p'
1  root:x:0:0:root:/root:/bin/bash
1  root:x:0:0:root:/root:/bin/bash
2  daemon:x:1:1:daemon:/usr/sbin:/bin/sh
3  bin:x:2:2:bin:/bin:/bin/sh
4  sys:x:3:3:sys:/dev:/bin/sh
5  sync:x:4:65534:sync:/bin:/bin/sync
....下面忽略

如果root找到,除了输出所有行,还会输出匹配行。

范例2:只打印包含模板的行。

$ nl /etc/passwd | sed -n '/root/p'
1  root:x:0:0:root:/root:/bin/bash
按照范例运行命令,查看结果是否与教程一致。