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
相关推荐
Jason_chen10 小时前
Linux 6.2 音频机制深度解析:AI驱动的低延迟音频与零信任音频安全架构
linux
下午写HelloWorld10 小时前
Linux系统及Ubuntu常用指令
linux·ubuntu·操作系统
lizhihai_9911 小时前
股市学习心得-AI 产业链核心标的梳理清单
大数据·服务器·人工智能·科技·学习
云计算磊哥@11 小时前
运维开发宝典026-MySQL02数据库表操作
运维·数据库·运维开发
weixin_5231853211 小时前
Collections.unmodifiableMap详解:真的不可修改吗?
java·linux·前端
黄同学real12 小时前
解决 Visual Studio Web Deploy 远程发布报 401 未授权 (ERROR\_USER\_UNAUTHORIZED)
服务器
天天进步201512 小时前
Tunnelto 源码解析 #9:控制服务器设计:Warp、WebSocket、Ping/Pong 与连接保活
运维·服务器·websocket
凡人叶枫12 小时前
Effective C++ 条款04:确定对象被使用前已先被初始化
java·linux·开发语言·c++·嵌入式开发
云栖梦泽13 小时前
玩转RK3506SDK
linux·嵌入式硬件
极客先躯13 小时前
高级java每日一道面试题-2026年02月01日-实战篇[Docker]-Docker Volume 的生命周期管理是怎样的?
java·运维·docker·容器·持久化·架构图·容器卷