Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I want to create this folder: $HOME/a/b/c/d while $HOME/a is not created! Is it possible by one line in Terminal?

share|improve this question

2 Answers 2

up vote 11 down vote accepted

You can use the command mkdir with -p option to create a folder inside another non-existent folder. Consider an example,

mkdir -p "$HOME/a/b/c/d"

Where the folders a,b,c and d do not exist in home before running the command. After execution of the command all these folders will be created recursively inside one another.

You can see from man mkdir

-p, --parents
          no error if existing, make parent directories as needed
share|improve this answer

Here is the answer to the question,below command will do the job you want in just the way you want :) This can be done with mkdir (make directory command) as shown below:

root@test:~# sudo mkdir -p /abcd/efgh/ijkl/mnop/qrst/uvwx/yz/  
root@test:~#   

If you want it to show you the directories it created while it is working then use verbose with it as shown below:

root@test:~# sudo mkdir -pv /abcd/efgh/ijkl/mnop/qrst/uvwx/yz/  
mkdir: created directory `/abcd'
mkdir: created directory `/abcd/efgh'  
mkdir: created directory `/abcd/efgh/ijkl'  
mkdir: created directory `/abcd/efgh/ijkl/mnop'  
mkdir: created directory `/abcd/efgh/ijkl/mnop/qrst'  
mkdir: created directory `/abcd/efgh/ijkl/mnop/qrst/uvwx'  
mkdir: created directory `/abcd/efgh/ijkl/mnop/qrst/uvwx/yz/'  
root@test:~#  

Enjoy!! :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.