11

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

0

2 Answers 2

17

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
1

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!! :)

Not the answer you're looking for? Browse other questions tagged .