Creation of Directories in Unix file system.
What exactly is a directory ?
we can say a directory is collection of files
where files can be stored which will be helpful for the user to search the file
Directory name Typical contents
/bin Commands and programs used by all the users of the system
/boot Files required by the boot loader
/dev CD/DVD-ROM, floppy drives, USB devices, etc.
/etc System configuration files
/home User data files
Syntax :
$mkdir <option> <directory name>
To check what options are available in mkdir we have man command
How to create Directory ?
$mkdir <dir name>
This will create a directory in the present location where the user is
1 2 3 4 5 6 7 8 9 10 11 12 |
[oracle@dba15 ~]$ ls files listener.ora shellscripting tnsnames.ora [oracle@dba15 ~]$ mkdir dir1 [oracle@dba15 ~]$ ls dir1 files listener.ora shellscripting tnsnames.ora [oracle@dba15 ~]$ ls -ld dir1/ drwxr-xr-x. 2 oracle dba 4096 Sep 26 19:09 dir1/ [oracle@dba15 ~]$ cd dir1/ [oracle@dba15 dir1]$ ls [oracle@dba15 dir1]$ pwd /home/oracle/dir1 [oracle@dba15 dir1]$ |
- $mkdir -p <dir1/dir2/dir3/>
Using this command we can create sub level directories
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[oracle@dba15 ~]$ ls dir1 files listener.ora shellscripting tnsnames.ora [oracle@dba15 ~]$ [oracle@dba15 ~]$ [oracle@dba15 ~]$ mkdir -p d1/d2/d3 [oracle@dba15 ~]$ ls d1 dir1 files listener.ora shellscripting tnsnames.ora [oracle@dba15 ~]$ cd d1 [oracle@dba15 d1]$ ls d2 [oracle@dba15 d1]$ cd d2 [oracle@dba15 d2]$ ls d3 [oracle@dba15 d2]$ cd d3 [oracle@dba15 d3]$ ls [oracle@dba15 d3]$ pwd /home/oracle/d1/d2/d3 |
We have created directory under another directory.
- $mkdir -m <permissions tag> <dir name>
At the time of creation we can create directory by assigning permissions to it
1 2 3 4 5 6 |
[oracle@dba15 ~]$ mkdir -m 777 d10 [oracle@dba15 ~]$ ls d1 d10 dir1 files listener.ora shellscripting tnsnames.ora [oracle@dba15 ~]$ ls -ld d10/ drwxrwxrwx. 2 oracle dba 4096 Sep 26 19:15 d10/ [oracle@dba15 ~]$ |
- Command CD stands for change directory .It is used to change the directory locations.
- $cd <dir name>
This command is used to enter from one directory to other directory
1 2 3 4 5 6 |
[oracle@dba15 ~]$ ls d1 d10 dir1 files listener.ora shellscripting tnsnames.ora [oracle@dba15 ~]$ mkdir text [oracle@dba15 ~]$ cd text/ [oracle@dba15 text]$ ls [oracle@dba15 text]$ |
- $ls -ld <dir name>
To list the permissions of directory.
1 2 3 4 5 |
[oracle@dba15 ~]$ ls d1 d10 dir1 files listener.ora shellscripting tnsnames.ora [oracle@dba15 ~]$ mkdir test1 [oracle@dba15 ~]$ ls -ld test1/ drwxr-xr-x. 2 oracle dba 4096 Sep 26 19:17 test1 |
ABSOLUTE PATH AND RELATIVE PATHS
ABSOLUTE PATH :
What ever the action performed by the user from the home directory by giving the exact address locations of the file or directory is known as absolute path
RELATIVE PATH :
What ever the action performed by the user from the present working directory by giving the exact address locations of the target file or directory is known as relative path
The Difference between Absolute and Relative paths :
To know the present directory location we have command called “PWD”
1 2 |
[oracle@dba15 ~]$ pwd /home/oracle |
Create directory called ‘d1’
1 2 3 4 |
[oracle@dba15 ~]$ mkdir -p d1 [oracle@dba15 ~]$ cd d1 [oracle@dba15 d1]$ pwd /home/oracle/d1 |
List out the files under ‘d1’ directory.
1 2 |
[oracle@dba15 d1]$ ls [oracle@dba15 d1]$ |
1 2 3 4 |
Create one more directory under 'd1' [oracle@dba15 d1]$ mkdir d2 [oracle@dba15 d1]$ ls d2 |
When we gave ls command it shows only d2 directory but we have two hidden directories
1 2 |
[oracle@dba15 d1]$ ls -a . .. d2 |
. is command which indicates current directory.
1 2 |
[oracle@dba15 d1]$ cd . [oracle@dba15 d1]$ |
.. is command which indicates parent directory.
1 2 3 4 5 6 7 |
[oracle@dba15 d1]$ cd d2 [oracle@dba15 d2]$ pwd /home/oracle/d1/d2 ##### for d2 the parent directory is d1. [oracle@dba15 d2]$ cd .. [oracle@dba15 d1]$ ls d2 |
– is one of the option in cd command to go for previous working directory.
1 2 |
[oracle@dba15 d1]$ cd - [oracle@dba15 d2]$ |
~ is one of the option in cd command to go for user home location.
1 2 |
[oracle@dba15 d2]$ cd ~ [oracle@dba15 ~]$ |
Thank you…