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
相关推荐
丶伯爵式4 分钟前
Ubuntu 新装后常用设置
linux·运维·ubuntu
@LuckY BoY4 分钟前
deepin 系统的导航栏或任务栏不见了
运维·服务器
哼?~6 分钟前
Socket编程准备
linux·网络
羌俊恩12 分钟前
Vim modeline 命令执行漏洞(CVE-2026-34714)修复指导
linux·编辑器·vim·漏洞·cve-2026-34714
wang090725 分钟前
Linux性能优化之中断
linux·运维·性能优化
bukeyiwanshui26 分钟前
20260410 系统启动原理
linux
huanmieyaoseng100327 分钟前
Linux 安装配置 Tomcat超详细2026新(附安装包)
linux·运维·tomcat
tianyuanwo1 小时前
Kickstart 自动化安装中的密码管理:rootpw 与 chpasswd 完全指南
运维·自动化·kickstart
Black蜡笔小新1 小时前
花屏/蓝屏/黑屏/画面抖动/冻结/模糊检测,聊聊EasyCVR的视频质量诊断插件,解决运维人的实际烦恼
运维·音视频
charlie1145141911 小时前
嵌入式Linux模块学习——insmod 底层全流程解剖:从用户命令到内核内存
linux·c·嵌入式linux