LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-30-2013, 01:05 AM   #1
Tauatioti
LQ Newbie
 
Registered: Oct 2013
Posts: 18

Rep: Reputation: Disabled
how to create directory in an existing directory with single command


Hi everyone

I need help on how can i use mkdir to create a directory in a existing directory with single command

Thanks

Taati
 
Old 11-30-2013, 01:08 AM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Is there an echo in here?
 
Old 11-30-2013, 01:12 AM   #3
Tauatioti
LQ Newbie
 
Registered: Oct 2013
Posts: 18

Original Poster
Rep: Reputation: Disabled
Hi

I have created a directory 'a' but i want to create another 2 directory inside directory a, what command can i use to create those 2 directory inside directory 'a' with single command

Thanks
 
Old 11-30-2013, 01:13 AM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
same as before...

Code:
mkdir -p a/b/c/d/e... as far as you want to go
... Oh, my mistake, I think you mean...

Code:
mkdir -p a/{b,c}
so you end up with a/, a/b and a/c

Last edited by astrogeek; 11-30-2013 at 01:19 AM.
 
Old 11-30-2013, 01:22 AM   #5
Tauatioti
LQ Newbie
 
Registered: Oct 2013
Posts: 18

Original Poster
Rep: Reputation: Disabled
Hi

Thank you for your quick reply, the command you just gave me is used for creating directory inside one another

My questions is how can i create 2 or 3 directory inside an existing directory with single command, for example, i have created directory A,later i want to create another 2 or 3 directory inside directory A, what command can do the task with single command

Thanks
 
Old 11-30-2013, 01:23 AM   #6
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Yea, I got that after I posted - see my previous post with amendment...

Code:
mkdir -p a/{b,c}
 
1 members found this post helpful.
Old 11-30-2013, 01:31 AM   #7
Tauatioti
LQ Newbie
 
Registered: Oct 2013
Posts: 18

Original Poster
Rep: Reputation: Disabled
Hi

Sory i didnt read your full comment i was just eager to follow your first command,

i really appreciate your help

it work perfectly

Thank you very much
 
Old 11-30-2013, 01:33 AM   #8
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
No problem.

FYI you can carry that to multiple depths like this...

Code:
mkdir -p a/{b,c,d/e/f,g}
Try it.
 
Old 11-30-2013, 03:45 AM   #9
Tauatioti
LQ Newbie
 
Registered: Oct 2013
Posts: 18

Original Poster
Rep: Reputation: Disabled
Hi

I had created directory using the command mkdir -p a/{b,c,d/e/f,g}, and my questions is how can i delete the directory 'b,c,d and g' only with the single command.

i already try this command

rmdir -p a/{b,c,g}
rm -f a/{b,c,g}

with no luck

Thanks
 
Old 11-30-2013, 04:00 AM   #10
Madhu Desai
Member
 
Registered: Mar 2013
Distribution: Rocky, Fedora, Ubuntu
Posts: 541

Rep: Reputation: 153Reputation: 153
Code:
rm -rf --preserve-root a/*
 
Old 11-30-2013, 04:01 AM   #11
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Quote:
Originally Posted by Tauatioti View Post
I had created directory using the command mkdir -p a/{b,c,d/e/f,g}, and my questions is how can i delete the directory 'b,c,d and g' only with the single command.
By removing d, you also remove e and f (not sure if you realize that).

Quote:
i already try this command

rmdir -p a/{b,c,g}
rm -f a/{b,c,g}

with no luck

Thanks
Your example doesn't include d. Try this, which leaves a, d (e and f) intact:
Code:
$ rm -rf a/{b,c,g}
 
1 members found this post helpful.
Old 11-30-2013, 04:04 AM   #12
Madhu Desai
Member
 
Registered: Mar 2013
Distribution: Rocky, Fedora, Ubuntu
Posts: 541

Rep: Reputation: 153Reputation: 153
Quote:
Originally Posted by Tauatioti View Post
Hi
rmdir -p a/{b,c,g}
rm -f a/{b,c,g}

with no luck
In that case,

Code:
rm -rf --preserve-root a/{b,c,g}
 
1 members found this post helpful.
Old 11-30-2013, 04:06 AM   #13
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
@mddesai: Why the --preserve-root? It is the default:
Quote:
--preserve-root
do not remove `/' (default)
 
2 members found this post helpful.
Old 11-30-2013, 04:11 AM   #14
Madhu Desai
Member
 
Registered: Mar 2013
Distribution: Rocky, Fedora, Ubuntu
Posts: 541

Rep: Reputation: 153Reputation: 153
Quote:
Originally Posted by druuna View Post
@mddesai: Why the --preserve-root? It is the default:
Hmmm..You are right. Its not required. but i think in case like the one in my previous post (rm -rf --preserve-root a/*), by giving --preserve-root, it will not delete directory 'a'.
 
Old 11-30-2013, 04:15 AM   #15
Madhu Desai
Member
 
Registered: Mar 2013
Distribution: Rocky, Fedora, Ubuntu
Posts: 541

Rep: Reputation: 153Reputation: 153
OK , --preserve-root is totally redundant. 'rm -rf a/*' wont remove 'a' either.

Last edited by Madhu Desai; 11-30-2013 at 04:18 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to create directory in an existing directory with single command Tauatioti Linux - Newbie 2 11-30-2013 02:17 AM
[SOLVED] create many directory with single command Tauatioti Linux - Newbie 3 11-29-2013 05:36 PM
Create a bash script that verifies an existing directory? AB1826 Linux - Newbie 11 12-13-2011 09:49 AM
Is there a way to make a new directory and then cd into with single command ? mynameisthomas Linux - Newbie 4 09-13-2009 01:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration