zoukankan      html  css  js  c++  java
  • [Bash] Create and Copy Multiple Files with Brace Expansions in Bash

    Copy

    Brace expansions are commonly used with the cp or mv commands in order to dynamically generate strings. In this lesson, we'll use a brace expansion to shorten a command like cp index.js index.js.backup to cp index.js{,.backup}. We'll also see how brace expansions can generate sequences. For example, touch test-{1..10} will generate the arguments to touch to create 10 test files.

    Note that the tree command that I use in this lesson has to be installed.

    Case 0:

    It acts like a loop

    echo pre-{a,b,c}-post
    ## pre-a-post pre-b-post pre-c-post
    echo pre-{,b,c}-post
    ## pre--post pre-b-post pre-c-post
    echo {1..10}
    ## 1 2 3 4 5 6 7 8 9 10
    echo {a..z}
    ## a b c d e f g h i j k l m n o p q r s t u v w x y z
    

    Case 1:

    copy index.js and create a backup file called index.js.backup

    cp index.js{,.backup}
    

    Case 2:

    Create multi nested folder with same structure

    mkdir -p packages/{pkg1,pkg2,pkg3}/src
    tree
    

    Case 3:

    Greate multi test files

    touch test-{1..3}.js
    
  • 相关阅读:
    查询缓存
    Indexes
    计院生活第三章 狂轰乱炸(上)
    JAVA实现文件树
    OGNL表达式语言介绍
    DOM4J使用教程
    css 优先级
    《JavaScript凌厉开发 Ext详解与实践》3月5日开始上架销售
    Drools 规则引擎
    OLTP和OLAP区别
  • 原文地址:https://www.cnblogs.com/Answer1215/p/14398082.html
Copyright © 2011-2022 走看看