Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linux

shell

mkdir

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.

like image 576
prasanthv Avatar asked Jan 31 '11 17:01

prasanthv


People also ask

How do you set a relative path?

Absolute and relative paths in script tools You can also set this option by right-clicking the script tool, clicking Properties, then clicking the General tab. At the bottom of the dialog box, check Store relative path names (instead of absolute paths).

How do I change a folder using relative path?

To change directories using absolute pathnames, type cd /directory/directory; to change directories using relative pathnames, type cd directory to move one directory below, cd directory/directory to move two directories below, etc.; to jump from anywhere on the filesystem to your login directory, type cd; to change to ...

How to move or copy files in subfolders to one folder?

Move or Copy Files in Subfolders to a Single Folder. 1 Open a Command Prompt window. 2 Run the following commands, one by one and press ENTER after each line: md "d:\all snaps" cd /d "d:\vacation snaps\2016" for /r %d in (*) do copy "%d" ...

How to create multiple folders in Linux?

The second method for creating multiple folders requires using the Batch (BAT) file. First you create a root folder in which you want your other folders to appear. Once done, create a text file in root folder and enter the md command in following way.

How to create multiple subfolders in Windows 10?

Next, type in the command "cd" (which stands for "change directory") and specify the path to the folder where you want to create more subfolders. Here's an example: Execute the command by pressing the Enter key. Set Up a New Folder: To set up new folders using command prompt, use the command "md" (stands for "make directory").

How do I create a separate folder for each month?

With this command you can create one or several folders. To create a separate folder for each month, you can follow the following format: When you press the Enter key, you won't see anything just yet. However, after you add the "dir" command and press Enter, the command prompt window will display the created folders.


2 Answers

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} 
like image 68
Dennis Williamson Avatar answered Sep 23 '22 19:09

Dennis Williamson


Use shell expansion :

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

That such an underestimated possibility :)

my2c

like image 32
neuro Avatar answered Sep 19 '22 19:09

neuro