当前位置:网站首页>管道和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
边栏推荐
- Fastdfs思维导图
- Selenium displays webdriverwait
- Centralized record of experimental problems
- Learn to C language fourth day
- Zhongchuang storage | how to choose a useful distributed storage cloud disk
- Go limit depth traversal of files in directory
- 41. 缺失的第一个正数
- 3-5通过XSS获取cookie以及XSS后台管理系统的使用
- 引入结构化并发,Swift 5.5 发布!
- matplotlib. Pyplot partition drawing
猜你喜欢
Deep analysis of C language pointer (Part I)
100天拿下11K,转岗测试的超全学习指南
笔记本电脑卡顿怎么办?教你一键重装系统让电脑“复活”
Cmake project under vs2019: calculating binocular parallax using elas method
How to use PM2 management application? Come in and see
又一款数据分析神器:Polars 真的很强大
Deep analysis of C language function
缓存淘汰算法初步认识(LRU和LFU)
一些接地气的话儿
Leetcode 542, 01 matrix
随机推荐
Unity asset import settings
Fastdfs思维导图
Syntax Error: TypeError: this. getOptions is not a function
又一款数据分析神器:Polars 真的很强大
Go限制深度遍历目录下文件
ros功能包内自定义消息引用失败
setInterval、setTimeout、requestAnimationFrame
mmap、munmap
Matlab: psychtoolbox installation
Another data analysis artifact: Polaris is really powerful
go defer
[SQL] string series 2: split a string into multiple lines according to specific characters
What about laptop Caton? Teach you to reinstall the system with one click to "revive" the computer
Selenium displays webdriverwait
Bash script learning -- for loop traversal
Come in and teach you how to solve the problem of port occupation
The more you use the computer, the slower it will be? Recovery method of file accidental deletion
Fastdfs mind map
Singleton mode
matplotlib. Pyplot partition drawing