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
相关推荐
温柔一只鬼.36 分钟前
Docker快速入门——Windowns系统下Docker安装(2025最新理解与完整,附带WSL1如何升级为WSL2)
运维·docker·容器
武文斌771 小时前
复习总结最终版:单片机
linux·单片机·嵌入式硬件·学习
驱动探索者1 小时前
贝尔实验室发展史:20世纪科技圣殿的辉煌与沉浮
linux
何朴尧2 小时前
centos/cuos如何开启软件源
linux·运维·centos
派阿喵搞电子2 小时前
关于使用docker部署srs服务器的相关指令
服务器·docker·容器
YouEmbedded2 小时前
解码Linux文件IO之标准IO
linux·文件io·系统io
qq_339191142 小时前
aws ec2防ssh爆破, aws服务器加固, 亚马逊服务器ssh安全,防止ip扫描ssh。 aws安装fail2ban, ec2配置fail2ban
服务器·ssh·aws
撬动未来的支点2 小时前
【Linux内核】Linux内核裁剪完全指南:从理论到实战的系统优化
linux
csdn_Hzx3 小时前
Linux添加一个系统服务
linux·运维·服务器
洛克大航海3 小时前
Ubuntu安装Hbase
大数据·linux·数据库·ubuntu·hbase