how to use | in Linux? give me an example

The | symbol in Linux is called a pipe. It is used to pass the output of one command as input to another command. Here is an example:

sh 复制代码
# List all files in the current directory and pass the output to the `grep` command to filter files containing "example"
ls -l | grep example

In this example:

  • ls -l lists all files in the current directory in long format.
  • The | pipe passes the output of ls -l to the grep command.
  • grep example filters the output to show only lines that contain the word "example".
bash 复制代码
root@DyanGong:~/trainingLog# ls -altr
total 44
drwxr-xr-x 2 root root 4096 Nov  1 14:08 1stNov2024
drwxr-xr-x 2 root root 4096 Nov  5 19:37 5thNov2024
-rw-r--r-- 1 root root   28 Nov 27 10:44 hello.sh
drwxr-xr-x 2 root root 4096 Nov 27 17:22 27thNov2024
drwxr-xr-x 2 root root 4096 Nov 28 16:15 28thNov2024
drwxr-xr-x 2 root root 4096 Nov 29 15:18 29thNov2024
-rw-r--r-- 1 root root   34 Dec  4 14:05 hello1.sh
drwxr-xr-x 2 root root 4096 Dec  4 16:53 4thDec2024
drwxr-xr-x 9 root root 4096 Dec  5 09:34 .
drwx------ 8 root root 4096 Dec  5 14:53 ..
drwxr-xr-x 3 root root 4096 Dec  5 15:09 5thDec2024
root@DyanGong:~/trainingLog# ls -l | grep Dec
drwxr-xr-x 2 root root 4096 Dec  4 16:53 4thDec2024
drwxr-xr-x 3 root root 4096 Dec  5 15:09 5thDec2024
-rw-r--r-- 1 root root   34 Dec  4 14:05 hello1.sh
相关推荐
2601_960567962 小时前
电商套图自动化效率的工程量化分析——从逐张生成到批量套图的架构演进
运维·架构·自动化
吳所畏惧2 小时前
宝塔面板Redis密码修改指南:SSH命令修改 vs 面板UI界面修改,哪个更靠谱?
运维·服务器·数据库·redis·缓存·ssh
DFT计算杂谈2 小时前
无 Root 权限在 Tesla K80 零门槛部署 DeepSeek 大模型
linux·服务器·网络·数据库·机器学习
HiDev_3 小时前
【非标自动化】2、认识元器件(确定目标)
运维·自动化
维天说3 小时前
CLI-Switch 2026年3月版历史设计:Hook、TTY 隔离与 JSON 状态
java·服务器·json
Zhang~Ling4 小时前
从 fopen 到 struct file:从零开始拆解 Linux 文件 I/O
linux·运维·服务器
DeeplyMind4 小时前
Linux 深入 per-VMA lock:Linux 缺页路径如何摆脱 mmap_lock
linux·per-vma lock
爱写代码的阿森4 小时前
鸿蒙三方库 | harmony-utils之PreferencesUtil首选项数据监听详解
服务器·华为·harmonyos·鸿蒙·huawei
爱写代码的森4 小时前
蒙三方库 | harmony-utils之FileUtil文件重命名与属性查询详解
linux·运维·服务器·华为·harmonyos·鸿蒙·huawei
中微极客4 小时前
2026主流AI Agent框架技术选型与性能对比
运维·网络·人工智能