开发者

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.


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}


Use shell expansion :

mkdir Labs/lab4a/{folder1,myfolder,foofolder}

That such an underestimated possibility :)

my2c


Go to console -

cd ...

mkdir {8...30}

Create multiple folders linux


I would use mkdir with the -p option as it creates intermediate directories as required :

mkdir -p ~/var/www/html/site1/{site2/{html,logs,images},site{3..6},site7}

this creates this output so in your case,

mkdir -p ~/Labs/lab4a/folder{1..3}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜