You are on page 1of 27

DEPARTMENT OF TECHNICAL

EDUCATION
Name
ANDHRA: Gandi
PRADESH
Govinda Naidu
Designation : Head of Computer Engg Section
Branch : Computer Engg
Institute : Govt.Polytechnic for Women,

Bheemunipatnam
Year / Semester : III Semester
Subject : UNIX & C
Subject Code : CM-304
Topic : Basics of UNIX
Duration : 50 Min
SubTopic : UNIX directory commands
Teaching Aids : PPT, Animations, Photographs
CM304.6 1
Recap

In previous period we learnt about


UNIX file commands

CM304.6 2
Objectives

On the completion of this period , you would be


able to know

UNIX directory commands

CM304.6 3
Directory

 Can hold files and other directories


root

temp UNIX
dev
etc bin user

user1 user2 usern

sbtet UNIX directory structure

Fig.1 result c CM304.6 4


Directory Commands
 pwd
 cd
 mkdir
 rmdir
 ls

CM304.6 5
directory?
 Files are grouped in the directory structure.
 The file-system is arranged like hierarchical tree
(inverted)structure.
 The top of the tree is called “root” which usually
contains several sub-directories.
 In UNIX “/”(forward slash) is used to present the
“root”.

CM304.6 6
The pwd command

 The pwd command displays the full path name


for the current working directory.
 Example
 $pwd
 /usr/nagendra Here /usr/nagendra is the
directory in which the user is currently working.
 The pwd command is useful when user is
moving around the file system. If the user lost
track of which directory is in, then he can use
pwd to checkout
CM304.6 7
The cd command

The cd command changes the working directory


$pwd
/usr/nagendra
$ cd ..
$pwd
/usr

CM304.6 8
The cd command Contd..

$cd nagendra
/usr/nagendra
$cd /
$pwd
/
 As shown above to move around in the file
system, cd command is used.

CM304.6 9
The ls command
The ls command is used to list the names of the
files in the directory.
When the user enters ls command an alphabetically
ordered listing of filenames will appear.
 Example:
$ls
Address
Advance
Books
Prices
Staff
$ CM304.6 10
The ls command
Contd..

 The output of ls command shows that there are


five files in the user directory. The ls command
has an -
 -l option which shows listing of files in long
format.

CM304.6 11
The ls command Contd..

$ls –l
total 5
-rw-rw-rw-1 nagendra 47 796 May 27 12:30 Addres
-rw-rw-rw- 1 nagendra 47 91 May 27 12:40 Advance
-rw-rw-rw- 1 nagendra 47 20 May 27 12:49 Books
-rw-rw-rw- 1 nagendra 47 89 May 27 12:00 Prize
-rw-rw-rw- 1 nagendra 47 123 May 27 12:09 Staff

CM304.6 12
The ls command Contd..

 The first column gives the file permissions for


each of the files.
 The first bit may contain either a – for ordinary
file, d for directory , c for character file, b for
block file and p for pipe files.
 The second column gives number of links to the
file. Link is anything but alias for a particular file.
CM304.6 13
The ls command Contd..

 The third column shows the user id of the owner


of the file.
 The fourth column gives file size in bytes.
 The next column gives the date and time of last
modifications made to the file .
 last column gives name of the file.

CM304.6 14
The ls command Contd..

‘ls-a‘ option lists all the files in the


directory including the special files
beginning with a ‘.’.

‘ls –r’ option lists all the files in the reverse


order.

‘ls –x ‘ option gives a sorted listing of the directory

in columns
CM304.6 15
The mkdir command
The mkdir command allow the user to create sub
directories. Let us consider the following
Example.
$pwd
/usr/nagendra Here the user is in /usr/nagendra

directory.
$mkdir jani here the user creating sub
directory jani under /usr/nagendra
CM304.6 16
The mkdir command Contd..

$cd jani
$pwd
$/usr/nagendra/jani
 The mkdir command creates a sub directory.
 However the current working directory does not
change to new directory.

CM304.6 17
The rmdir command

 If the user is not requiring a directory he can


remove the directory by using ‘rmdir’ command.
 The directory which is to be deleted must be
empty(not contains files or subdirectories) and it
should not be the current directory.
 Directory or parent directory.

CM304.6 18
The rmdir command Contd..

Example:
$pwd
/usr/nagendra/jani
$cd ..
$pwd
/usr/nagendra

CM304.6 19
Summary
At the end of this class, you have learnt
UNIX file commands like
pwd – displaying present working directory.
cd – change directory
ls – list files/directory
mkdir – creates directory
rmdir – removes directory

CM304.6 20
Quiz

1.pwd means -------

(a) copy
(b) move
(c) Present working directory
(d) Print document

CM304.6 21
Quiz

1.pwd means -------

(a) copy
(b) move
(c) Present working directory
(d) Print document

CM304.6 22
Quiz

2.In UNIX cd is used---- directory

(a) copy

(b) concate

(c) cancel

(d) change
CM304.6 23
Quiz

2.In UNIX cd is used---- directory

(a) copy

(b) concate

(c) cancel

(d) change
CM304.6 24
Quiz

3.In UNIX rmdir is used to -- dir

(a) remove
(b) rearrange
(c) repeat
(d) Remove empty

CM304.6 25
Quiz

3.In UNIX rmdir is used to -- dir

(a) remove
(b) rearrange
(c) repeat
(d) Remove empty

CM304.6 26
Frequently asked questions

1.Explain UNIX directory commands.

2. Differentiate between mkdir and rmdir.

3. What is a pwd?

4. How to change directory in UNIX?

CM304.6 27

You might also like