01 January 2012

Creating Directory in Linux/Unix

Leave a Comment
How to Create Directory in Linux/Unix 
                                                          
                                                        Empty directory can be created using mkdir command in Linux/Unix.


Syntax:
                   mkdir [-option] directoryname

Example


$ pwd
/home/sandeep
$ mkdir sandeep1
$ cd sandeep1
$ pwd
/home/sandeep/sandeep1
$

                
a. We can also  create multiple directories  using mkdir command

Example


             mkdir d1 d2 d3

Above command create three directories name d1 , d2 , d3.


$ pwd
/home/sandeep/css
$ ls
d1 d2 d3 file1 index.html mewfile
$ mkdir d7 d8 d9
$ ls
d1 d2 d3 d7 d8 d9 file1 index.html mewfile
$




b. We can also create directory tree with the help of mkdir command with just one invocation.

Example


           mkdir  pdir  pdir/ch1   pdir/ch1/ch2

The above command first create directory pdir , then ch1 as  sub-directory of pdir and ch2 as sub-directory of ch1.

$ pwd
/home/sandeep
$ mkdir pdir pdir/ch1 pdir/ch1/ch2
$ cd pdir
$ pwd
/home/sandeep/pdir
$ ls
ch1
$ cd ch1
$ ls
ch2
$

* if we have written  mkdir pdir/ch1  pdir/ch1/ch2  pdir . Then system will fail to create ch1 and ch2 directory but it will create pdir .

* if system fail to create a directory then this may be due to 
a. The Directory may already exist
b. There may be an ordinary file with the same name.
c.Due to the Permissions set for the Current Directory.

If You Liked This Post Please Take a Time To Share This Post

You May Also Like...

0 comments:

Post a Comment