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 小时前
详解共享WiFi小程序怎么弄!
大数据·运维·网络·人工智能·小程序·生活
yanzhyan1 小时前
【Linux】Linux命令:free
linux·运维·服务器
web前端神器1 小时前
服务器机房迁移,centos系统root无法登录,也无法联网等问题
运维·服务器·centos
木偶☜2 小时前
Node.js接收文件分片数据并进行合并处理
服务器·javascript·arcgis·node.js
编程墨客2 小时前
IO进程----进程
linux·服务器·microsoft
可涵不会debug2 小时前
【C++】在线五子棋对战项目网页版
linux·服务器·网络·c++·git
清风-云烟2 小时前
使用redis-cli命令实现redis crud操作
java·linux·数据库·redis·spring·缓存·1024程序员节
Rm3 小时前
Linux 防火墙 Systemctl 常用命令速查
linux
孤寂大仙v3 小时前
【Linux】环境变量
linux·运维·服务器
稳联技术3 小时前
DeviceNet转Profinet网关+FANUC机器人:打造工业界的灭霸手套,掌控无限可能
运维·服务器