Directory commands in UNIXUNIX FILES,UNIX structure ,General Features of UNIX commands||Command Structure||Commands of UNIX
DIRECTORY COMMANDS
pwd: CHECKING YOUR CURRENT DIRECTORY :
- Any time user can know the current working directory using pwd command.
$ pwd
/home/kumar
- Like HOME it displays the absolute path
cd: CHANGING THE CURRENT DIRECTORY :
User can move around the UNIX file system using cd (change directory) command. When used with the argument, it changes the current directory to the directory specified as
argument, progs:
$ pwd/home/kumar
$cd progs$ pwd/home/kumar/progs
Here we are using the relative pathname of progs directory. The same can be done with the absolute
pathname also.
mkdir: MAKING DIRECTORIES :
Directories are created with mkdir (make directory) command. The command is followed by names of the directories to be created. A directory patch is created under current directory like this:
$ mkdir patch
You can create a number of subdirectories with one mkdir command:
$mkdir patch dba doc
- For instance the following command creates a directory tree:
$mkdir progs progs/cprogs progs/javaprogs
- This creates three subdirectories – progs, cprogs and javaprogs under progs.
- The order of specifying arguments is important. You cannot create subdirectories before creation of parent directory.
- For instance following command doesn‘t work
$mkdir progs/cprogs progs/javaprogs progs
- mkdir: Failed to make directory “progs/cprogs”;
- No such directory mkdir: Failed to make directory “progs/javaprogs”; No such directory
System refuses to create a directory due to fallowing reasons:
- The directory is already exists.
- There may be ordinary file by that name in the current directory.
- User doesn‘t have permission to create directory.
rmdir: REMOVING A DIRECTORY :
rmdir expect the arguments reverse of mkdir.
The rmdir (remove directory) command removes the directories. You have to do this to remove
progs:
$ rmdir progs
- If progs is empty directory then it will be removed form system. Following command used with mkdir fails with rmdir
$ rmdir progs progs/cprogs progs/javaprogsrmdir: directory “progs”: Directory not empty
- First subdirectories need to be removed from the system then parent.
Following command works with rmdir
$ rmdir progs/cprogs progs/javaprogs progs
- First it removes cprogs and javaprogs form progs directory and then it removes Progs from system.
- rmdir : Things to remember
- You can‘t remove a directory which is not empty
- You can‘t remove a directory which doesn‘t exist in system.
- You can‘t remove a directory if you don‘t have permission to do so
ABSOLUTE AND RELATIVE PATHNAME :
ABSOLUTE PATHNAME :
Directories are arranged in a hierarchy with root (/) at the top. The position of any file within the
hierarchy is described by its pathname. Elements of a pathname are separated by a /. A pathname is absolute, if it is described in relation to
root, thus absolute pathnames always begin with a /.
Following are some examples of absolute filenames.
/etc/passwd
/users/kumar/progs/cprogs
/dev/rdsk/Os3
Example: date command can executed in two ways as
$date // Relative pathThu Sep 7 10:20:29 IST 2017
$/bin/date // Absolute pathThu Sep 7 10:20:29 IST 2017
RELATIVE PATHNAME :
- A pathname can also be relative to your current working directory.
- Relative pathnames never begin with /.
- Relative to user home directory, some pathnames might look like this –
progs/cprogs rdsk/Os3
Tags:
unix