简体   繁体   中英

touch command create multiple files (different names) under one directory

I wanted to make a script that creates a directories and files structure in bash.

I tried something like this:

"mkdir -p 1/2 && touch 1/2/{a b c}"

a,b,c should be files created in one command or something..

but for some reason the structure goes like this

current folder: b c 1

1: 2

2: a

touch can't be used to create multiple files with different names in one directory?

我建议添加,

mkdir -p 1/2 && touch 1/2/{a,b,c}
mkdir -p 1/2 && touch 1/2/{a,b,c}

The commas are essential, otherwise it is evaluated to 1/2/{abc} . Whitespace is only allowed in such patterns if it is escaped:

echo a{1\ 2\ 3,4} # echo a1 2 3 a4

如果您不喜欢逗号或需要按顺序创建文件名,请使用“ ..”

mkdir -p 1/2 && touch 1/2/{a..c}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM