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
相关推荐
Kaede62 分钟前
如何选择合适的服务器操作系统
运维·服务器
无名3872 分钟前
用 openssl 测试 tls 连接
运维·服务器
Johny_Zhao10 分钟前
Ubuntu安装部署Zabbix网络监控平台和设备配置添加
linux·网络·mysql·网络安全·信息安全·云计算·apache·zabbix·shell·yum源·系统运维·itsm
chennalC#c.h.JA Ptho34 分钟前
kubuntu系统详解
linux·数据库·经验分享·postgresql·系统安全
熙曦Sakura39 分钟前
【Linux网络】HTTPS
linux·网络·https
铁锚41 分钟前
一个WordPress连续登录失败的问题排查
java·linux·服务器·nginx·tomcat
华颉科技1 小时前
机架式服务器是什么?机架式/塔式/刀片式三大服务器类型区别与选型全解析
服务器·科技·服务器类型·刀片服务器·机架服务器·塔式服务器
DavieLau1 小时前
Python开发后端InfluxDB数据库测试接口
服务器·数据库·python·时序数据库
程序视点1 小时前
Linux中find命令用法核心要点提炼
linux·linux命令·linux指令·linux的find命令
生命不息战斗不止(王子晗)1 小时前
mybatis中${}和#{}的区别
java·服务器·tomcat