Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

linux - How do I make multiple folders in a single location using relative path to the location?

What I'm trying to do is create a number of folders in the "~/Labs/lab4a/" location (~/Labs/lab4a/ already exists).

Say I want folder1, folder2, folder3 all in the lab4a folder.

This isn't about making nested folders all at one go using the mkdir -p command or going in to lab4a and just making multiple folders at one go. I'm wondering is there a faster way using mkdir to create multiple folders in the same location using relative path.

i.e prompt~/: mkdir Labs/lab4a/folder1 folder2 folder3 To create all those folders in lab4a at once.

question from:https://stackoverflow.com/questions/4854277/how-do-i-make-multiple-folders-in-a-single-location-using-relative-path-to-the-l

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In Bash and other shells that support it, you can do

mkdir ~/Labs/lab4a/folder{1..3}

or

mkdir ~/Labs/lab4a/folder{1,2,3}

Other options:

mkdir $(seq -f "$HOME/Labs/lab4a/folder%03g" 3)

mkdir $(printf "$HOME/Labs/lab4a/folder%03g " {0..3})

Which will give you leading zeros which make sorting easier.

This will do the same thing in Bash 4:

mkdir ~/Labs/lab4a/folder{001..3}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...