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
相关推荐
霍夫曼1 小时前
UTC时间与本地时间转换问题
java·linux·服务器·前端·javascript
2301_810746312 小时前
CKA冲刺40天笔记 - day20-day21 SSL/TLS详解
运维·笔记·网络协议·kubernetes·ssl
❀͜͡傀儡师2 小时前
docker 部署 komari-monitor监控
运维·docker·容器·komari
物联网软硬件开发-轨物科技2 小时前
【轨物方案】软硬件一体赋能,开启矿山机械远程智慧运维新篇章
运维
月熊2 小时前
在root无法通过登录界面进去时,通过原本的普通用户qiujian如何把它修改为自己指定的用户名
linux·运维·服务器
大江东去浪淘尽千古风流人物3 小时前
【DSP】向量化操作的误差来源分析及其经典解决方案
linux·运维·人工智能·算法·vr·dsp开发·mr
打码人的日常分享3 小时前
智慧城市一网统管建设方案,新型城市整体建设方案(PPT)
大数据·运维·服务器·人工智能·信息可视化·智慧城市
赖small强4 小时前
【Linux驱动开发】NOR Flash 技术原理与 Linux 系统应用全解析
linux·驱动开发·nor flash·芯片内执行
风掣长空4 小时前
Google Test (gtest) 新手完全指南:从入门到精通
运维·服务器·网络
luback4 小时前
前端对Docker简单了解
运维·docker·容器