Linux Tips and Tricks

Linux Tips and Tricks

Creat Directories and Sub Directories in one command

October31

We use mkdir command to create directories. In the mkdir command we have a option called -p, which is used to create directory and sub directories in one shot.

kamaraj@kamaraj-laptop:~/Desktop/testing/test$ man mkdir | grep -A2 “\-p”
-p, –parents
no error if existing, make parent directories as needed

Example :

I am going to create directory in the below manner.

a directory contains the directory b
b directory contains the directory c
c directory contains the directory d

kamaraj@kamaraj-laptop:~/Desktop/testing$ cd test/
$ tree
.

0 directories, 0 files
$ pwd
/home/kamaraj/Desktop/testing/test
$ ls -lrt
total 0
$ mkdir -p a/b/c/d
$ ls -lrt
total 4
drwxr-xr-x 3 kamaraj kamaraj 4096 2010-10-31 12:05 a

$ tree
.
`-- a
       `-- b
             `-- c
                   `-- d
4 directories, 0 files

$

tree command is used to display the directory structure in the tree format ( parents and its childs )

posted under Uncategorized

Email will not be published

Website example

Your Comment:


Recent Comments

    Categories