zoukankan      html  css  js  c++  java
  • 【linux命令】命名管道(mkfifo)+ 结合xargs命令使用

    管道( | ):将上一个命令的标准输出结果作为后一个命令的标准输入(进程间的通讯,只在同意终端)

    命令管道:可用于任何进程之间的通讯(可在不同终端间),用mkfifo命令创建

    [root@rhel8 ~]# mkfifo /tanbaobao/p_file
    [root@rhel8 ~]# ls -l /tanbaobao/p_file 
    prw-r--r-- 1 root root 0 6月   5 08:25 /tanbaobao/p_file
    [root@rhel8 ~]# file /tanbaobao/p_file 
    /tanbaobao/p_file: fifo (named pipe)

    不同终端使用命令管道进行通讯

    # 终端1
    [root@rhel8 ~]# tty
    /dev/pts/0
    [root@rhel8 ~]# who
    root     pts/0        2020-06-05 07:11 (192.168.187.1)
    root     pts/1        2020-06-05 08:26 (192.168.187.1)
    ## 将命令放入管道文件中
    [root@rhel8 ~]# rpm -aq > /tanbaobao/p_file
    
    # 终端2
    [root@rhel8 ~]# tty
    /dev/pts/1
    ## 另一终端提取(提取出来后管道文件中的命令为空,就可以另外在放入命令进去)
    [root@rhel8 ~]# grep openssh /tanbaobao/p_file 
    openssh-server-8.0p1-3.el8.x86_64
    openssh-clients-8.0p1-3.el8.x86_64
    openssh-8.0p1-3.el8.x86_64

    xargs命令(将上条命令结果作为下条命令的参数)

    如:找出某文件将其删除或找出某进程将它结束

    ## 需求:/tanbaobao/dir1目录下目录aaa和5个文件file1~file5,需将目录下5个文件删除
    
    # 方法如下:
    ## 不能删除
    [root@rhel8 dir1]# find /tanbaobao/dir1/ -name file* | rm -rf
    ## 接xargs能删除
    [root@rhel8 tanbaobao]# find /tanbaobao/dir1/ -name file* | xargs rm -rf
    ## find /tanbaobao/dir1/ -name file* -exec rm -rf {} ;
    ## find /tanbaobao/dir1/ -name file* -delete
    # 命令 【可选项】 参数
    选项:
    -n:指定单行显示的参数个数
    -d:定义分割符,默认以空格或换行符
  • 相关阅读:
    LeetCode. 476. Number Complement
    LeetCode 172.Factorial Trailing Zeroes
    原码,反码,补码笔记
    python3笔记
    django笔记(python web框架)
    mysql 8.0 主从复制配置
    centos 7系统安装mysql 8.0
    MobaXterm无法退格删除
    Oracle数据泵常用命令
    oracle查年度周末日期
  • 原文地址:https://www.cnblogs.com/HeiDi-BoKe/p/13051522.html
Copyright © 2011-2022 走看看