[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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2019-02-11 [HTML5] Add an SVG Image to a Webpage and Get a Reference to the Internal Elements in JavaScript
2019-02-11 [Angular] Angular i18n Alternative Expressions Support (select)
2019-02-11 [React + Functional Programming ADT] Create Redux Middleware to Dispatch Multiple Actions
2019-02-11 [React + Functional Programming ADT] Connect State ADT Based Redux Actions to a React Application
2019-02-11 [Functional Programming ADT] Create a Redux Store for Use with a State ADT Based Reducer
2019-02-11 [CSS3] Make a One-time CSS Animation that Does Not Revert to its Original Style
2017-02-11 [Ramda] Eliminate Function Arguments (Point-Free Style) with Ramda's Converge