creating a directory and subdirectories using bash?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-1
down vote

favorite












Here's a sample output what it should look like when the bash script is executed --> https://imgur.com/jfuKEdf .



My question is about how do we make this or what code can I use?







share|improve this question
















  • 3




    1) Post the desired output in your question instead of a link to a photo. 2) Provide what you have tried so far and where you're stuck.
    – Nasir Riley
    Apr 10 at 5:11











  • @Nish: Have a look at the -p option of mkdir.
    – user1934428
    Apr 10 at 5:49














up vote
-1
down vote

favorite












Here's a sample output what it should look like when the bash script is executed --> https://imgur.com/jfuKEdf .



My question is about how do we make this or what code can I use?







share|improve this question
















  • 3




    1) Post the desired output in your question instead of a link to a photo. 2) Provide what you have tried so far and where you're stuck.
    – Nasir Riley
    Apr 10 at 5:11











  • @Nish: Have a look at the -p option of mkdir.
    – user1934428
    Apr 10 at 5:49












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











Here's a sample output what it should look like when the bash script is executed --> https://imgur.com/jfuKEdf .



My question is about how do we make this or what code can I use?







share|improve this question












Here's a sample output what it should look like when the bash script is executed --> https://imgur.com/jfuKEdf .



My question is about how do we make this or what code can I use?









share|improve this question











share|improve this question




share|improve this question










asked Apr 10 at 5:04









Nish

11




11







  • 3




    1) Post the desired output in your question instead of a link to a photo. 2) Provide what you have tried so far and where you're stuck.
    – Nasir Riley
    Apr 10 at 5:11











  • @Nish: Have a look at the -p option of mkdir.
    – user1934428
    Apr 10 at 5:49












  • 3




    1) Post the desired output in your question instead of a link to a photo. 2) Provide what you have tried so far and where you're stuck.
    – Nasir Riley
    Apr 10 at 5:11











  • @Nish: Have a look at the -p option of mkdir.
    – user1934428
    Apr 10 at 5:49







3




3




1) Post the desired output in your question instead of a link to a photo. 2) Provide what you have tried so far and where you're stuck.
– Nasir Riley
Apr 10 at 5:11





1) Post the desired output in your question instead of a link to a photo. 2) Provide what you have tried so far and where you're stuck.
– Nasir Riley
Apr 10 at 5:11













@Nish: Have a look at the -p option of mkdir.
– user1934428
Apr 10 at 5:49




@Nish: Have a look at the -p option of mkdir.
– user1934428
Apr 10 at 5:49










1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










for dir in a a/b a/b/c a/b/c/d; do
mkdir "$dir" && touch "$dir/$dir##*/"1..100
done


That is, loop through the directory names that we'd like to create, and for each directory:



  1. create it, and

  2. create empty files in it.

$dir##*/ will expand to the basename of the directory in $dir, e.g. to c if $dir is a/b/c. The brace expansion something1..100 will expand to something1 something2 ... something100.



A variation that is easier to expand to an arbitrary depth:



dir=''
for dirname in a b c d; do
dir="$dir:-./$dirname"
mkdir "$dir" && touch "$dir/$dir##*/"1..100
done


Here, $dir:-. will be replaced by . if $dir is unset or empty, which it will be on the first iteration. This means that $dir will be built up to be first ./a, then ./a/b etc.



If you want further subdirectories, e.g. all the way down to z:



dir=''
for dirname in a..z; do
dir="$dir:-./$dirname"
mkdir "$dir" && touch "$dir/$dir##*/"1..100
done





share|improve this answer






















  • thanks for that. I executed that command but it actually only went until D[1..100] nothing after that. "4 directories, 400 files"
    – Nish
    Apr 10 at 6:57











  • @Nish See updated answer.
    – Kusalananda
    Apr 10 at 7:00










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f436680%2fcreating-a-directory-and-subdirectories-using-bash%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










for dir in a a/b a/b/c a/b/c/d; do
mkdir "$dir" && touch "$dir/$dir##*/"1..100
done


That is, loop through the directory names that we'd like to create, and for each directory:



  1. create it, and

  2. create empty files in it.

$dir##*/ will expand to the basename of the directory in $dir, e.g. to c if $dir is a/b/c. The brace expansion something1..100 will expand to something1 something2 ... something100.



A variation that is easier to expand to an arbitrary depth:



dir=''
for dirname in a b c d; do
dir="$dir:-./$dirname"
mkdir "$dir" && touch "$dir/$dir##*/"1..100
done


Here, $dir:-. will be replaced by . if $dir is unset or empty, which it will be on the first iteration. This means that $dir will be built up to be first ./a, then ./a/b etc.



If you want further subdirectories, e.g. all the way down to z:



dir=''
for dirname in a..z; do
dir="$dir:-./$dirname"
mkdir "$dir" && touch "$dir/$dir##*/"1..100
done





share|improve this answer






















  • thanks for that. I executed that command but it actually only went until D[1..100] nothing after that. "4 directories, 400 files"
    – Nish
    Apr 10 at 6:57











  • @Nish See updated answer.
    – Kusalananda
    Apr 10 at 7:00














up vote
1
down vote



accepted










for dir in a a/b a/b/c a/b/c/d; do
mkdir "$dir" && touch "$dir/$dir##*/"1..100
done


That is, loop through the directory names that we'd like to create, and for each directory:



  1. create it, and

  2. create empty files in it.

$dir##*/ will expand to the basename of the directory in $dir, e.g. to c if $dir is a/b/c. The brace expansion something1..100 will expand to something1 something2 ... something100.



A variation that is easier to expand to an arbitrary depth:



dir=''
for dirname in a b c d; do
dir="$dir:-./$dirname"
mkdir "$dir" && touch "$dir/$dir##*/"1..100
done


Here, $dir:-. will be replaced by . if $dir is unset or empty, which it will be on the first iteration. This means that $dir will be built up to be first ./a, then ./a/b etc.



If you want further subdirectories, e.g. all the way down to z:



dir=''
for dirname in a..z; do
dir="$dir:-./$dirname"
mkdir "$dir" && touch "$dir/$dir##*/"1..100
done





share|improve this answer






















  • thanks for that. I executed that command but it actually only went until D[1..100] nothing after that. "4 directories, 400 files"
    – Nish
    Apr 10 at 6:57











  • @Nish See updated answer.
    – Kusalananda
    Apr 10 at 7:00












up vote
1
down vote



accepted







up vote
1
down vote



accepted






for dir in a a/b a/b/c a/b/c/d; do
mkdir "$dir" && touch "$dir/$dir##*/"1..100
done


That is, loop through the directory names that we'd like to create, and for each directory:



  1. create it, and

  2. create empty files in it.

$dir##*/ will expand to the basename of the directory in $dir, e.g. to c if $dir is a/b/c. The brace expansion something1..100 will expand to something1 something2 ... something100.



A variation that is easier to expand to an arbitrary depth:



dir=''
for dirname in a b c d; do
dir="$dir:-./$dirname"
mkdir "$dir" && touch "$dir/$dir##*/"1..100
done


Here, $dir:-. will be replaced by . if $dir is unset or empty, which it will be on the first iteration. This means that $dir will be built up to be first ./a, then ./a/b etc.



If you want further subdirectories, e.g. all the way down to z:



dir=''
for dirname in a..z; do
dir="$dir:-./$dirname"
mkdir "$dir" && touch "$dir/$dir##*/"1..100
done





share|improve this answer














for dir in a a/b a/b/c a/b/c/d; do
mkdir "$dir" && touch "$dir/$dir##*/"1..100
done


That is, loop through the directory names that we'd like to create, and for each directory:



  1. create it, and

  2. create empty files in it.

$dir##*/ will expand to the basename of the directory in $dir, e.g. to c if $dir is a/b/c. The brace expansion something1..100 will expand to something1 something2 ... something100.



A variation that is easier to expand to an arbitrary depth:



dir=''
for dirname in a b c d; do
dir="$dir:-./$dirname"
mkdir "$dir" && touch "$dir/$dir##*/"1..100
done


Here, $dir:-. will be replaced by . if $dir is unset or empty, which it will be on the first iteration. This means that $dir will be built up to be first ./a, then ./a/b etc.



If you want further subdirectories, e.g. all the way down to z:



dir=''
for dirname in a..z; do
dir="$dir:-./$dirname"
mkdir "$dir" && touch "$dir/$dir##*/"1..100
done






share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 10 at 7:00

























answered Apr 10 at 6:52









Kusalananda

102k13200317




102k13200317











  • thanks for that. I executed that command but it actually only went until D[1..100] nothing after that. "4 directories, 400 files"
    – Nish
    Apr 10 at 6:57











  • @Nish See updated answer.
    – Kusalananda
    Apr 10 at 7:00
















  • thanks for that. I executed that command but it actually only went until D[1..100] nothing after that. "4 directories, 400 files"
    – Nish
    Apr 10 at 6:57











  • @Nish See updated answer.
    – Kusalananda
    Apr 10 at 7:00















thanks for that. I executed that command but it actually only went until D[1..100] nothing after that. "4 directories, 400 files"
– Nish
Apr 10 at 6:57





thanks for that. I executed that command but it actually only went until D[1..100] nothing after that. "4 directories, 400 files"
– Nish
Apr 10 at 6:57













@Nish See updated answer.
– Kusalananda
Apr 10 at 7:00




@Nish See updated answer.
– Kusalananda
Apr 10 at 7:00












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f436680%2fcreating-a-directory-and-subdirectories-using-bash%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay