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
    
  • 相关阅读:
    Prism-超轻量的开源框架
    1的数目
    二叉树中和为某一值得路径
    把二叉树打印成多行
    对称的二叉树
    二叉树的下一个节点
    删除链表中重复的结点
    数组中的重复数字
    连表中环入口的节点
    把字符串换成整数
  • 原文地址:https://www.cnblogs.com/Answer1215/p/14398082.html
Copyright © 2011-2022 走看看