What are Unix Directory Commands with examples| Create Directory in Unix

Unix Directory :

In previous articles I explained about basic unix commands and how to work with unix files with examples.In this article i will give how to work with unix directory with real life examples.You can create directory in unix,can be able  to move directory,place files in directory,copy the files in directory using multiple commands.I will try to explain each and every command related to directory in this article.Unix uses hierarchical structure of files and directories.Unix Directory

“A directory in simple terms is a file or folder which contains different files and folders.”

Unix Directory  with examples :

Home Directory (/) :

When user first log in to the unix server,the specified directory is called as Home directory.Home directory is Unix Directory which is indicated by / sign.User needs to do much more work in home directory only.

To Go to Home Directory from any location:

Command :

$cd ~


To Go to any users Home Directory :


$cd ~ username


To go into a last directory then use following command:

Command :

$cd –


PWD Command :

PWD stands for Present Working Directory.This is most used linux command to see the specific Unix Directory on which the user is working on.




$cd .. To come out from current working directory.

Command :

$cd ..


$ cd / :- It changes to root directory.


 $ cd /


$ pwd

$/ [directly comes to root directory]

Question: How to shift from Root directory to User (Home) directory?


E.g.– $ cd Directory_name

$ cd home


Question: How to see directories?


To See the list of Directory names following command is used

Command :

$Ls Directory name

$Ls home/amit


Create Directory in Unix/ Mkdir Command :

user can create the directory using Mkdir command in unix.

Syntax :

$Mkdir Directory_name


$Mkdir Amit

Mkdir command is used to create  Unix Directory in present working directory.If user wants to create directory on the specific path then just use following syntax:

Syntax :

$Mkdir path/Directory_name


$Mkdir usr/bin/Amit

The above statement will create directory in usr/bin folder.Mkdir command produces no output if successfully created directory.

Creating multiple directories :

User can create multiple directories in unix using following command.

Syntax :

$Mkdir directory1 directory2….directory..n


$Mkdir Amit Rahul

Above statement will create 2 different directories named ‘Amit’ and ‘Rahul’ in present working directory.

Creating Parent directory:

Sometimes user wants to create a directory where the specified directory is not exist.Means user is trying to create parent directory.

$mkdir /tmp/Pradnya/Unix
mkdir: Failed to make directory "/tmp/Pradnya/Unix"; 
No such file or directory $

If user is facing above error then user needs to use -p option which is used to create parent directory and all the necessary directories directly.

Example :

$mkdir -p /tmp/Pradnya/Unix

The above statement will create the directory named ‘Pradnya’ in tmp folder and ‘Unix’ in ‘Pradnya’ folder.

rmdir command for removing directory:

To remove directory user will have use rmdir command which stands for ‘Removing Directory’.Before removing directory user needs to check that the specified directory is empty or there is no any file or subdirectory inside that directory.


$rmdir directory_name


$rmdir Amit


The above statement will remove the directory named ‘Amit’.

User can remove multiple directories at a same time using following command:


$rmdir directory_name1 directory_name2…..directory_name..n


$rmdir Amit Rahul


The above statement will remove 2 directories named Amit and Rahul.Rmdir command produces no output if it successfully runs and removes the directory.

$ rmdir:- It removes a directory but directory must be empty.

E.g. $ rmdir Directory_name

$ rm – r Directory_name:-It deletes recursively entire directory structure

$ rm – ri Directory_name:- It deletes recursively entire directory structure with confirmation

$ rm – rf Directory_name:- It deletes recursively entire directory structure with forcibly

CD command for Changing Directories:

One of the most used command in unix is Cd which changes the directory path.User can be able to go to any specified path using cd command.


$cd directory-path


directory path is path of directory which you want to change.


$cd usr/amit/bin


The above statement will go to the bin directory and user will able to work in ‘Bin‘ Directory.

Renaming Directories using mv command :

Using mv command user will rename the directory name.

Syntax :

$mv Old_directory New_directory

Example :

$mv Amit pradnya

The above mv statement is used to rename the directory named ‘Amit’ to ‘Pradnya’.

Copying files:-

$ cp :- To copy a file.

E.g.– $ cp Source_File Target_File

Note:Source file must be existing file and target file may be a new file/existing file.

$mv: To Rename/Movea file or directory.


$ mv old_file new_file (old file is renamed/moved to new file)

$ mv old_directory new_directory (old directory is renamed/moved to new directory)

For any confirmation use (-i)


$ cp                             àCopy & Paste

$ mv                            àCut & Paste

Creating Hidden files:

Any file_name/directory_name starts with ‘.’ is hidden file/directory.

E.g.– $ cat > .file_name         $ mkdir .directory_name


Ctrl+d [To save & close file]

$ mv emp .emp         àHide existing file

$mv .emp emp          à Unhide existing file

$ mv abc .abc            à Hide directory

$ mv .abc abc                        à Unhide directory

Viewing list of files:-


$ ls                                           àIt list current directory all files & sub – directories in ascending order based on                                                             ASCII Values.

$ ls -a                                      àIt list all files along with hidden files.

$ ls -r                                       àIt list all files in reverse order (Descending)

$ ls – R                                    àIt list all files recursively.

$ ls – t                         àIt list all files based on date & time of creation.

$ ls – l                                      àIt list all files in long list format. i.e.9 fields.

$ ls – l File_Name                   àIt list the file in long list format. i.e.9 fields.

What is .(dot) and . .(dot dot) in Unix :

In UNIX, (.) means the current directory, so typing cd .

NOTE: there is a space between cd and the dot.

Means stay where you are (the unixstuff directory).

This may not seem very useful at first, but using (.) as the name of the current directory will save a lot of typing.

The parent directory (..)

(..) Means the parent of the current directory, so typing cd .. Will take you one directory up the hierarchy (back to your home directory).

Note: Typing cd with no argument always returns you to your home directory. This is very useful if you are lost in the file system. And, cd / takes directly to Root Directory.

Click on Topic You want to learn:

  1. History of SQL
  2. SQL Create Table(DDL in SQL)
  4. SQL Select Statement Execution
  5. Operators in SQL
  6. Views in SQL
  7. Materialized View in SQL
  8. Joins in SQL
  9. Inner Join / Outer Join
  10. Full Outer Join / Cartesian Join
  11. Union and Union ALL
  12. Intersect and Minus
  13. Indexing in SQL
  14. Rank and Dense Rank
  15. SubQueries and Correlated Subqueries
  16. Parser and Optimizer
  17. Oracle 11 G new Features
  18. SQL Functions List
  19. Constraints in SQL
  20. Database Normalization
  21. Table Partitioning
  22. Pivot in SQL
  23. Difference Between Truncate,Delete and drop
  24. Oracle System Tables

Unix Tutorials :

1.What is unix?

2.Basic unix commands

3.File Commands in unix

4.Create File in Unix using multiple ways

5.Cat Command

6.Touch Command

7.Mkdir command

8.rmdir Command

9.pwd command

10.Cd Command

11.cut Command

12.paste Command

13.tr Command

14.Cp Command

15.wc command

16.cmp command

17.Rm Command

18.Grep Command

19.Egrep Command

20.FGrep Command

Hope Everyone will get idea about these basic unix commands related to directory.If you like this article dont forget to comment in comments section.