zoukankan      html  css  js  c++  java
  • Linux命令之yes

    在删除文件或进行一些乱七八糟的危险操作时总需要用户手动输入一个"y"来确定一下,但是如果数量很多的话手动输入就是个灾难啊,yes最初就是为了解决这个问题产生的,比如这种形式:

    yes | rm a*

    当然我们可以指定-f静默选项不进行确认询问,呃,就当我举了个不太恰当的例子吧,毕竟我删除文件从来都是-f选项,而借助yes的话太麻烦了。

    不过它的另一个用法可能大多数人都不知道,就是可以指定一行字符串然后不断将这行字符串送到标准输出,实际上yes本来的作用就是接收一行字符串然后不断将它输出,如果未指定的话默认就是y,这个是写在手册里的:

    Repeatedly output a line with all specified STRING(s), or 'y'.

    所以没事啃下手册还是有些用处的,这个特性可以将yes当做“crazy-repeat”使用(我瞎取的名字,不过还挺形象的),即将一行字符串不断的重复输出到标准输出:

    yes "foobar"

    在某些情况下可以用来模拟数据产生的过程,比如模拟日志疯狂产生的过程:

    yes "[2018-08-08 18:30:17] Thread-10 : foo bar"

    总结:

    1. yes用来将指定字符串不断送到标准输出,如果未指定字符串的话默认就是y,如果进程不被杀掉会一直发送直到天荒地老。

    2. 在某些情况下可以用来模拟不断产生的数据,优点是实现简单,缺点是每行数据都是一样的不会变,不如写个脚本模拟。

    最后附上文档man yes:

    YES(1)                                                            User Commands                                                           YES(1)
    
    NAME
           yes - output a string repeatedly until killed
    
    SYNOPSIS
           yes [STRING]...
           yes OPTION
    
    DESCRIPTION
           Repeatedly output a line with all specified STRING(s), or 'y'.
    
           --help display this help and exit
    
           --version
                  output version information and exit
    
           GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report yes translation bugs to <http://translationproject.org/team/>
    
    AUTHOR
           Written by David MacKenzie.
    
    COPYRIGHT
           Copyright © 2013 Free Software Foundation, Inc.  License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
           This is free software: you are free to change and redistribute it.  There is NO WARRANTY, to the extent permitted by law.
    
    SEE ALSO
           The  full documentation for yes is maintained as a Texinfo manual.  If the info and yes programs are properly installed at your site, the
           command
    
                  info coreutils 'yes invocation'
    
           should give you access to the complete manual.
    
    GNU coreutils 8.22                                                 April 2018                                                             YES(1)
    

    .

  • 相关阅读:
    arcgis要素转json
    GeoJSON.js:221 Uncaught Error: Invalid GeoJSON object.
    深入学习SAP UI5框架代码系列之一:UI5 Module的懒加载机制
    SAP Spartacus简介
    金庸逝世两周年纪念日:一个失意程序员的呓语
    一个用于SAP UI5学习的脚手架应用,没有任何后台API的依赖
    通过最简单的button控件,深入学习SAP UI5框架代码系列之零
    如何使用SAP UI5 SDK网站查询指定控件的属性如何使用
    一行代码将SAP CDS view数据以ALV的方式输出
    演讲预告:一个月的住院经历,我悟到了哪些和程序员职场发展相关的心得
  • 原文地址:https://www.cnblogs.com/cc11001100/p/9539623.html
Copyright © 2011-2022 走看看