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
    
  • 相关阅读:
    HDU1266 Reverse Number
    codevs1380 没有上司的舞会
    codevs1163 访问艺术馆
    codevs2144 砝码称重 2
    codevs1553 互斥的数
    codevs1230 元素查找
    codevs3118 高精度练习之除法
    codevs1245 最小的N个和
    codevs1063 合并果子
    codevs1052 地鼠游戏
  • 原文地址:https://www.cnblogs.com/Answer1215/p/14398082.html
Copyright © 2011-2022 走看看