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
相关推荐
大侠归来10 分钟前
Docker 部署 Dolibarr:从零开始的完整指南
运维·docker·容器
KING-WU51218 分钟前
Linux GDB 调试实战指南:从编译到断点调试
linux·运维·服务器
Lucis__20 分钟前
深入理解程序链接与加载—从动静态链接到库加载
linux·elf·链接·程序·动静态库
傲世仙尊22 分钟前
类和对象中-构造函数与析构函数把初始化清理自动化
java·运维·自动化
七月吃橘子29 分钟前
WSL2+Docker+Ollama,本地部署大模型实践(Qwen1.8b)
运维·docker·容器
贵州诚鑫致达科技有限公司29 分钟前
PVID 是什么?端口参数三身份
服务器·经验分享
影视飓风TIM35 分钟前
Linux 进程信号原理与剖析
linux·运维·服务器
缘友一世1 小时前
开源 Linux截图工具闪构(SnapForge)
linux·运维·ubuntu·开源·截图
iCxhust1 小时前
先想好如何测试:让测试驱动你的程序设计
运维·服务器·软件工程·编程的艺术
Philtell1 小时前
突然连接不上内网服务器的问题
运维·服务器