creating a directory and subdirectories using bash?
Clash 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?
bash
add a comment |Â
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?
bash
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
add a comment |Â
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?
bash
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?
bash
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
add a comment |Â
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
add a comment |Â
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:
- create it, and
- 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
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
add a comment |Â
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:
- create it, and
- 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
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
add a comment |Â
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:
- create it, and
- 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
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
add a comment |Â
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:
- create it, and
- 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
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:
- create it, and
- 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
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
add a comment |Â
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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