LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to create directory in an existing directory with single command (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-create-directory-in-an-existing-directory-with-single-command-4175486323/)

Tauatioti 11-30-2013 01:05 AM

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

astrogeek 11-30-2013 01:08 AM

Is there an echo in here?

Tauatioti 11-30-2013 01:12 AM

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

astrogeek 11-30-2013 01:13 AM

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

Tauatioti 11-30-2013 01:22 AM

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

astrogeek 11-30-2013 01:23 AM

Yea, I got that after I posted - see my previous post with amendment...

Code:

mkdir -p a/{b,c}

Tauatioti 11-30-2013 01:31 AM

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

astrogeek 11-30-2013 01:33 AM

No problem.

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

Code:

mkdir -p a/{b,c,d/e/f,g}
Try it.

Tauatioti 11-30-2013 03:45 AM

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

Madhu Desai 11-30-2013 04:00 AM

Code:

rm -rf --preserve-root a/*

druuna 11-30-2013 04:01 AM

Quote:

Originally Posted by Tauatioti (Post 5072857)
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}

Madhu Desai 11-30-2013 04:04 AM

Quote:

Originally Posted by Tauatioti (Post 5072857)
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}

druuna 11-30-2013 04:06 AM

@mddesai: Why the --preserve-root? It is the default:
Quote:

--preserve-root
do not remove `/' (default)

Madhu Desai 11-30-2013 04:11 AM

Quote:

Originally Posted by druuna (Post 5072868)
@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'.

Madhu Desai 11-30-2013 04:15 AM

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


All times are GMT -5. The time now is 11:09 PM.