LinuxQuestions.org
Visit Jeremy's Blog.
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, 02: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, 02:08 AM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 3,884
Blog Entries: 1

Rep: Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000
Is there an echo in here?
 
Old 11-30-2013, 02: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, 02:13 AM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 3,884
Blog Entries: 1

Rep: Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000
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 02:19 AM.
 
Old 11-30-2013, 02: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, 02:23 AM   #6
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 3,884
Blog Entries: 1

Rep: Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000
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, 02: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, 02:33 AM   #8
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 3,884
Blog Entries: 1

Rep: Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000
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, 04: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, 05:00 AM   #10
mddnix
Member
 
Registered: Mar 2013
Location: Bangalore, India
Distribution: Redhat, Arch, Ubuntu
Posts: 512

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

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
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, 05:04 AM   #12
mddnix
Member
 
Registered: Mar 2013
Location: Bangalore, India
Distribution: Redhat, Arch, Ubuntu
Posts: 512

Rep: Reputation: 139Reputation: 139
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, 05:06 AM   #13
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
@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, 05:11 AM   #14
mddnix
Member
 
Registered: Mar 2013
Location: Bangalore, India
Distribution: Redhat, Arch, Ubuntu
Posts: 512

Rep: Reputation: 139Reputation: 139
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, 05:15 AM   #15
mddnix
Member
 
Registered: Mar 2013
Location: Bangalore, India
Distribution: Redhat, Arch, Ubuntu
Posts: 512

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

Last edited by mddnix; 11-30-2013 at 05:18 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 03:17 AM
[SOLVED] create many directory with single command Tauatioti Linux - Newbie 3 11-29-2013 06:36 PM
Create a bash script that verifies an existing directory? AB1826 Linux - Newbie 11 12-13-2011 10: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 02:29 PM


All times are GMT -5. The time now is 08:28 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration