当前位置:网站首页>管道和xargs
管道和xargs
2022-04-23 20:49:00 【贪睡的蜗牛】
ps aux|grep deltest|grep -v grep|awk '{print $2}'|xargs kill -9ps aux会列出所有的进程,后面碰到管道会将结果传递给第二个命令
第二个命令会从第一个命令的结果中查找deltest
第三个命令是反向过滤文本,会将包含grep的删除
第四个命令将会读取第三个命令删选的结果的第二列数据,awk默认通过空格隔开
xargs命令是用于给其他命令传递参数的一个过滤器,也是组合多个命令的一个工具。
将标准输入数据转换成功命令行参数能够将管道或者标准输入里的数据转换成特定命令的命令行参数
第五个命令会将前面的命令当成kill 的参数进而杀死


xargs
如果想要运行当前目录里的某个文件,可以使用python3 `pwd`/deltest2.py
也可以使用pwd | xargs -I {} python3 {}/deltest2.py
这个-I{}应该是把前面传过来的内容放到{},然后再次使用{}为使用
而echo `pwd|xargs -I {} python3 {}/$element`应该是想输出运行返回值,如果程序一直运行,那么将一直等待。
让多个程序运行的sh命令
#!/bin/bash
array=("deltest2.py" "deltest.py")
cd /workplace/kill_test
nowpath='/workplace/kill_test/'
for element in ${array[@]}
do
echo $element
nohup pwd|xargs -I {} python3 {}/$element &
sstr=$(echo -e $str)
echo $sstr
done
批量让程序停止
#!/bin/bash
#尽量写全运行的程序,最好把后缀也加上 数组元素之间没有逗号
array=("deltest2.py" "deltest.py")
for element in ${array[@]}
do
ps aux|grep $element|grep -v grep|awk '{print $2}'|xargs kill -9
done
版权声明
本文为[贪睡的蜗牛]所创,转载请带上原文链接,感谢
https://blog.csdn.net/baidu_41553551/article/details/124362244
边栏推荐
- 6-5 string - 2 String copy (assignment) (10 points) the C language standard function library includes the strcpy function for string copy (assignment). As an exercise, we write a function with the sam
- Lunch on the 23rd day at home
- How to use PM2 management application? Come in and see
- Sequential state
- What about laptop Caton? Teach you to reinstall the system with one click to "revive" the computer
- MySQL 存储过程和函数
- 打新债中签以后怎么办,网上开户安全吗
- Some thoughts on super in pytorch, combined with code
- Leetcode-279-complete square number
- MySQL基础之写表(创建表)
猜你喜欢

41. 缺失的第一个正数

100天拿下11K,转岗测试的超全学习指南

电脑越用越慢怎么办?文件误删除恢复方法

GO语言开发天天生鲜项目第三天 案例-新闻发布系统二

How to configure SSH public key in code cloud

A login and exit component based on token

go defer

41. The first missing positive number

Syntax Error: TypeError: this. getOptions is not a function

On IRP from the perspective of source code
随机推荐
GO语言开发天天生鲜项目第三天 案例-新闻发布系统二
An error occurs when the addressable assets system project is packaged. Runtimedata is null
Win 11K in 100 days, super complete learning guide for job transfer test
MySQL进阶之数据的增删改查(DML)
Graph traversal - BFS, DFS
Centralized record of experimental problems
The more you use the computer, the slower it will be? Recovery method of file accidental deletion
Communication between RING3 and ring0
GSI-ECM工程建设管理数字化平台
Minecraft 1.12.2模组开发(四十三) 自定义盾牌(Shield)
Tensorflow1. X and 2 How does x read those parameters saved in CKPT
Sequential state
居家第二十三天的午饭
浅谈数据库设计之三大范式
A login and exit component based on token
Awk example skills
Google 尝试在 Chrome 中使用 Rust
go reflect
Thinking after learning to type
Addition, deletion, modification and query of advanced MySQL data (DML)