Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword
Like this
19Activity
0 of .
Results for:
No results containing your search query
P. 1
Directory Commands

Directory Commands

Ratings:

5.0

(1)
|Views: 266|Likes:
Published by ninadchandekar

More info:

Published by: ninadchandekar on Jul 06, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

12/08/2012

pdf

text

original

 
UNIT-IDirectory Commands1. The pwd Command
It is remarkable feature of the UNIX system that both a file, as well as a human user,occupy a certain slot in the system. This command is used to determine the current directory is"Present Working Directory". It has no options and no attributes. When executes, it prints theabsolute pathnames for the current directory. When you log in to the system, UNIXautomatically places you in a directory called the home directory. In Most cases, this directory isalso your login directory, and the name of this home directory is usually the login name. Unlessyou change your directory, this will be called your current directory as well. It is created by thesystem when a user account in opened. If you log in using the login name Kumar, you will landup in a directory having the pathname /user/Kumar (unless you chosen to be placed in a sub-directory under this directory).You ca always find out the directory where you are current placed, by using the pwd (presentworking directory) command:
$ pwd
/usr/kumar 
2. Changing Directories- The cd Command
You can move around in the file system by using the
cd
(change directory). To changeyour current location in the file system hierarchy, use the cd (change directory) command,followed by an argument defining where you want to go. The arguments can be either anabsolute path to the destination, or a relative path. When used with an argument, it resembles itsMSDOS conterpart. It changes the current directory to the directory specified as the argument.You can use it to switch to the directory
progs:$ pwd
/usr/kumar 
$cd progs$pwd
/usr/kumar/progs
$_ 
Though
pwd
displays the absolute pathname,
cd
doesn't need to use one. The command
cd progs
here means that you should change your sub-directory to
progs
(under the current directory).Using an absolute pathname causes no harm either; user cd
/usr/kumar/progs
for the sameeffect.When you need to switch to the
/bin
directory where most of the commonly used UNIXcommands are kept, then you should use the absolute pathname
:$ pwd
/usr/kumar/progs
1
 
7 cd /
 bin
$ pwd/
 bin
$
 
 _ 
cd can also be used without any arguments.
$ pwd
/usr/kumar/progs
$
cd
$ pwd
/usr/kumar 
$
 
 _ 3. Making a Directories- The mkdir Command
Just as in MSDOS, directories can be created by using the
mkdir
(make directory)command. The command is followed by the names of the directories to be created. A directory
pis
is created under the current directory by using this name as the argument to the command.The basic syntax is:Mkdire directory_name
$ mkdir pis$
 
 _ 
Unlike MSDOS, however, a number of sub-directories can be created by one
mkdir
command
:$ mkdir pis pis/progs
 
pis/data$
 
 _ 
This create three sub-directories-
pis
, and two sub-directories in the just created sub-directory
pis
.The order of specifying the arguments is important
:
you obviously can't create a sub-directory before creation of its parent directory. For instance, you can't enter.
$ mkdir pis/progs pis/data pis
mkdir 
:
can't access
pis/
.Mkdir 
:
can't access
pis/
.
$
 
 _ 
The
pis
directory will still be created spite of the terse message from the system about its failureto create the sub-directories
progs
and data.Sometimes, the system refuses to create a directory
:$ mkdir
testmkdir 
:
can't make directory test
$
 
 _ 
2
 
This can happen when the directory test already exists, or the user doesn't have adequateauthorisaction to create a directory. This will be considered in some details while dealing withfile permissions.
4. Removing Directories- The rmdir Command
The
rmdir
(remove directory) command removes directories. Like mkdir, it can delete more thanone directory with a single command. For instance, the three directories and the sub-directoriesthat were just created with
mkdir
can be removed by using
rmdir
with a reversed set of arguments
:
The basic Syntax:rmdir directory_name
$ rmdir pis/progs pis/data pis$
 
 _ 
 Notice that when you delete sub-directories, as well as their parent directory (
pis
, this case), thelogic to be applied will have to b the reverse of the one used in creating directory with the
mkdir
command. The following sequence is invalid
:$ rmdir pis pis/progs pis/datarmdir: pis
not empty
$
 
 _ 
This error message leads to two important rules that you should remember while deletingdirectories. You can't delete a directory unless it is empty. In this case the
pis
directory couldn't be removed because of the existence of the sub-directories
progs
and
data
under it. Even thoughthe system flashed the error message, it silently deleted the two sub-directories
progs
and data.You now delete the
pis
directory using the same command but with a single argument
:$ rmdir pis$
 
 _ 
The rm command, used with the –r can also be used to remove directories. The rmdir commandwill first remove the contents of the directory, and then remove the directory itself.The other important rule is that you can't remove a sub-directory unless you are placed in adirectory which is hierarchically above the one you have chosen to remove. For instance, youcan't remove the
pis
directory by executing the command from the
pis
directory itself. Try doingthat
:$ cd pis$ pwd/usr/kumar/pis$ rmdir pisrmdir: pis
non-existent
$
 
 _ 
3

Activity (19)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads
Kuldeep Singh liked this
in1ne7a20 liked this
in1ne7a20 liked this
Sabby Dhillon liked this
gauravjain83 liked this
romiswara liked this
mike carvell liked this
ALi liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->