1. R.D.SIVAKUMAR, M.Sc.,M.Phil.,M.Tech.,
Assistant Professor of Computer Science &
Assistant Professor and Head, Department of M.Com.(CA),
Ayya Nadar Janaki Ammal College,
Sivakasi – 626 124.
Mobile: 099440-42243
e-mail : sivamsccsit@gmail.com
website: www.rdsivakumar.blogspot.in
Directory Commands
2. Directory Commands
The first thing that you are expected to know is some fundamental
concepts of commands. The general format of a command is:
Command option argument
Not all commands need the “option” and “argument”. Some needs option alone some
needs argument alone and while others need both.
For example ls (abbreviation for list but do not try to help the system by typing list
instead of ls. This helping action is greeted with an error message. The command ls saves
you from typing two more characters, but it adds human memory load.) command works
without option and argument, with argument alone, with option alone and with both.
Argument usually refers the name of the file on which the command should work with.
It should start with an alphabet. Some system files called dot files start with a . (dot).
3. Directory Commands
In the Fig. 3.1 even though there are two bins and two personal directories,
they can be uniquely identified by the system because of the path name. The path
names for the bin directories are /bin and / usr/bin. The first slash (/) always
represents the root directory.
As already stated, a slash before the first directory in the path, represents the
root. Path name also applies to files. The file is created within a directory by
specifying a name. The system identifies the file with filename combined with the
path of the directories from the root to the file’s directory.
Path names are of two types. They are
1. the Absolute path name and
2. the Relative path name.
An absolute path name is the complete path name of a file or directory
starting with root directory.
A relative path name begins with your working directory. It is the path of the file
relative to your working directory.
4. Directory Commands
Changing the Current Directory
The cd (change directory) command changes the current directory to the
specified directory. For example the current user ilamathi wants to switch over
from her home directory to /usr/bin. She first finds out the current directory to
ascertain her position and then she switches over to /usr/ bin. She executes the
following commands at the command prompt.
[ilamathi@localhost ilamathi] $ pwd
/home/ilamathi
[ilamathi@localhost ilamathi] $ cd /usr/bin
[ilamathi@localhost bin ] $ pwd
/usr/bin
If she wants to move to parent directory of the current directory then she has
to use cd .. at the $ prompt. cd command will not show the directory on the
screen. To show the directory, pwd command should be given at the $ prompt.
Note: The double dots (..) denote the path of parent directory. The single dot(.)
represents the directory itself. There should be a blank space between cd and ..
and there should be no blank space between the two dots
5. Directory Commands
Creating a Directory
The user kumaran wants to create an insurance directory under his health
directory. He is already in the health directory. He should make use of mkdir (make
directory) command.
This command creates the directory specified after the mkdir command, under
the current directory. But the newly created directory will not become the current
directory automatically. If you want move to the newly created directory you have
to make use of cd command.
[kumaran@localhost health] $ mkdir insurance
A new directory under health is created. You can specify the full path to make a
directory with mkdir command
6. Directory Commands
Removing a Directory
When there is a provision to make a directory, there should be a provision to
remove a directory also. Can you guess the command? Yes, you are right! It is
rmdir (remove directory).
Example:
[kumaran@localhost health] $ rmdir insurance
If you want remove a directory, the directory
1) should be empty and
2) should not be the current directory.
Kumaran did not store any thing in the insurance and the current directory is
only health not insurance. So, it is possible to delete the insurance directory.
If you want to remove a directory, which is not empty, you can make use of rm
command, which will be discussed shortly. As in the case of mkdir command, you
can use full path.
7. Directory Commands
Listing the Contents of a Directory
Suppose you want to find out the name of the files and the subdirectories of a
directory, ls is the only candidate to achieve this. For example the user Kumaran
wants to know the names of the files and directories of
/home/kumaran, he must give the following command.
[kumaran@localhost kumaran] $ ls /home/kumaran
healthcprogramming c++programming personal.
[kumaran@localhost kumaran] $ ls - F
health / cprogramming c++ programming personal /
The option -F adds / at the end of the directories and sub-directories.