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
相关推荐
wkj0012 分钟前
QuaggaJS 配置参数详解
java·linux·服务器·javascript·quaggajs
藥瓿亭38 分钟前
K8S认证|CKS题库+答案| 5.日志审计
linux·运维·docker·云原生·容器·kubernetes·cka
coder_lorraine1 小时前
【Linux系列】Linux用户大揭秘:从“公寓住户”到“社区管理员”的奇幻之旅
linux
家庭云计算专家1 小时前
飞牛云一键设置动态域名+ipv6内网直通访问内网的ssh服务-家庭云计算专家
运维·云计算·ssh·nextcloud·ddns·动态域名解析
藥瓿锻2 小时前
2024 CKA题库+详尽解析| 15、备份还原Etcd
linux·运维·数据库·docker·容器·kubernetes·cka
bbsh20992 小时前
WebFuture:Ubuntu 系统上在线安装.NET Core 8 的步骤
linux·ubuntu·.netcore·webfuture
太阳之神aboluo2 小时前
压测软件-Jmeter
java·运维·jmeter
ZZZKKKRTSAE2 小时前
快速上手Linux全局搜索正则表达式(grep)
linux·服务器·正则表达式
有谁看见我的剑了?2 小时前
stress 服务器压力测试的工具学习
服务器·学习·压力测试
有谁看见我的剑了?2 小时前
stress-ng 服务器压力测试的工具学习
服务器·学习·压力测试