当前位置:网站首页>管道和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 stored procedures and functions
- MySQL进阶之数据的增删改查(DML)
- Resolve the eslint warning -- ignore the warning that there is no space between the method name and ()
- 深入探究ASP.NET Core读取Request.Body的正确方式
- 41. The first missing positive number
- Psychological formula for converting RGB to gray value
- Opencv reports an error. Expected PTR < CV:: UMAT > for argument '% s'‘
- Thinking after learning to type
- UKFslam
- setInterval、setTimeout、requestAnimationFrame
猜你喜欢
Graph traversal - BFS, DFS
Come in and teach you how to solve the problem of port occupation
Write table of MySQL Foundation (create table)
缓存淘汰算法初步认识(LRU和LFU)
Unity solves Z-fighting
[SQL] string series 2: split a string into multiple lines according to specific characters
Resolve the eslint warning -- ignore the warning that there is no space between the method name and ()
What about laptop Caton? Teach you to reinstall the system with one click to "revive" the computer
Identifier CV is not defined in opencv4_ CAP_ PROP_ FPS; CV_ CAP_ PROP_ FRAME_ COUNT; CV_ CAP_ PROP_ POS_ Frames problem
Deep analysis of C language pointer (Part I)
随机推荐
2021-06-29 C escape character cancellation and use
Chrome 94 引入具有争议的 Idle Detection API,苹果和Mozilla反对
3-5 obtaining cookies through XSS and the use of XSS background management system
MySQL基础之写表(创建表)
学会打字后的思考
如何发挥测试策略的指导性作用
Awk print special characters
Summary and effect analysis of methods for calculating binocular parallax
打新债中签以后怎么办,网上开户安全吗
41. The first missing positive number
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
Factory mode
Leetcode 709, convert to lowercase
How to learn software testing? Self study or training? After reading this article, you will understand
wait、waitpid
Matlab: psychtoolbox installation
Prim、Kruskal
matplotlib. Pyplot partition drawing
Rust更适合经验较少的程序员?
Addition, deletion, modification and query of advanced MySQL data (DML)