DEV Community

Cover image for UNIX - DIRECTORIES
Tina Popli
Tina Popli

Posted on

UNIX - DIRECTORIES

Directories provide a better way of organizing files within the system. As we have file system in UNIX System, the directories can further contain sub directories too!

When we log in to the system, we are located into a particular directory that is our HOME Directory.

We can freely navigate in between different directories but the directory we are positioned at a particular point of time, that is referred to as CURRENT WORKING DIRECTORY.

SOME OF THE COMMANDS!

1) PWD
Pwd command displays the full path of your present/current working directory.

SYNTAX:
$ pwd

Sample Output:
/home/tina

ABSOLUTE AND RELATIVE PATHNAME

There are two ways a file can be accessed:
1) ABSOLUTE PATH NAME
2) RELATIVE PATH NAME

1) ABSOLUTE PATH NAME
It is the complete path name right from the root that UNIX follows to reach a particular file.
It starts with a slash ("/").

For example: to access a file named "newfile" which resides under sub directory "files", which is in the home directory, the absolute path will be : /home/files/newfile

2) RELATIVE PATH NAME
A Path name which is shortened and related to your current working directory. Relative path name is represented by a dot (.)
So to access a particular file, we will start from our present directory. Giving a relative reference starting from the current
directory rather than searching from a root.

SAMPLE: ./files/newfile

If similarly we want to specify the parent directory of the current directory, we can use double dots ("..")

../../files/newfile

Now that we know where we are currently using pwd, let us see how we can change to a new directory from our present working directory.

2) CD

SYNTAX:

cd [directory]

where directory is the name of the directory that we want to change to.

Let us assume the present directory is /user/tina

Example:
_$ pwd_
/user/tina

  • To move to the root directory

$ cd /
where the slash denotes the root directory as already discussed.

To move to another directory we will use the path name such as:

$ cd /user/stud

To move to the home directory:

$cd

  • We can use either absolute or relative pathnames to change directory.

NOTE:
1) cd ../ will take you to the parent directory.
2) cd ../../ takes you to the parent's parent directory

...To be continued! :)

Top comments (0)