当前位置:网站首页>管道和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
边栏推荐
- Mysql database common sense storage engine
- 浅谈数据库设计之三大范式
- Resolve the eslint warning -- ignore the warning that there is no space between the method name and ()
- Realrange, reduce, repeat and einops in einops package layers. Rearrange and reduce in torch. Processing methods of high-dimensional data
- MySQL stored procedures and functions
- Go limit depth traversal of files in directory
- Minecraft 1.12.2模组开发(四十三) 自定义盾牌(Shield)
- ros功能包内自定义消息引用失败
- 3-5 obtaining cookies through XSS and the use of XSS background management system
- 如何发挥测试策略的指导性作用
猜你喜欢
A login and exit component based on token
[SQL] string series 2: split a string into multiple lines according to specific characters
Common problems in deploying projects with laravel and composer for PHP
41. The first missing positive number
Identifier CV is not defined in opencv4_ CAP_ PROP_ FPS; CV_ CAP_ PROP_ FRAME_ COUNT; CV_ CAP_ PROP_ POS_ Frames problem
Common commands of MySQL in Linux
Leetcode 542, 01 matrix
Zhongchuang storage | how to choose a useful distributed storage cloud disk
Linux中,MySQL的常用命令
3-5 obtaining cookies through XSS and the use of XSS background management system
随机推荐
JSX syntax rules
How to learn software testing? Self study or training? After reading this article, you will understand
An error occurs when the addressable assets system project is packaged. Runtimedata is null
笔记本电脑卡顿怎么办?教你一键重装系统让电脑“复活”
IOT 设计与开发
3-5通过XSS获取cookie以及XSS后台管理系统的使用
UKFslam
Communication between RING3 and ring0
Solve importerror: cannot import name 'imread' from 'SciPy misc‘
Google 尝试在 Chrome 中使用 Rust
100天拿下11K,转岗测试的超全学习指南
Unity Odin ProgressBar add value column
The problem of 1 pixel border on the mobile terminal
go struct
go array
缓存淘汰算法初步认识(LRU和LFU)
go slice
Leetcode 709, convert to lowercase
Leetcode 20. Valid parentheses
Another data analysis artifact: Polaris is really powerful