what are . and .. directories?

what are . and .. directories? it is see every where when i try to view hidden files using ls command. Whats its purpose. Even when i create a directory and try to view hidden files in that directory i can see these . and .. directories.:confused:

Welcome to Unix.

. is a link to the current directory and .. the parent directory

try

cd ../

now

ls ./

is it a type of file? if so when i try rm -rf .. it doesnot show any error as if it removed it successfuly. but when i type ls -a it again shows up. i know cd .. will take you to parent directory of current dir.

# ls -al | more
total 157250
drwxrwxrwt  10 root     sys         1536 Jun 16 19:45 .
drwxr-xr-x  46 root     sys         1024 Oct 21  2010 ..

This is the permissions of those files.

Why do you think cd .. takes you up a directory?

What happens if you are in /export/home/chidori and you type

cd ../../

and why ?

How could you delete a resource that is in use,?

try removing .. / in bash, /bin/sh is a slightly cryptic shell for a novice.

1 Like

those are only needed for "navigation" into your directory/filesystem.
(single dot) stands for the current directory.
(double dot) stands for the parent directory of the actual working directory.

Example:

 
/export/home/user1 (the double dot / or parent) directory is /export/home

If your working directory is /export/home/user1 and you would like to change on level higher you can use the double dot instead of the full path.
Example:

[root@saxmgt01 user1]# pwd (print working directory)
/export/home/user1

[root@saxmgt01 user1]# cd /export/home/
[root@saxmgt01 home]# pwd
/export/home

is the same as:
[root@saxmgt01 user1]# pwd
/export/home/user1
[root@saxmgt01 user1]# cd ..
[root@saxmgt01 home]# pwd
/export/home

 
1 Like

Okay thanks to all... but now do you mean this file is linked to some other file? so can i tweak some file which can change the meaning

. which means currect dir
.. which means parent dir

. and .. are not files and not links. Take a look at the output of ls -ld ./ ../ . They're both prefixed by a 'd', which means they are directories.

The idea behind this is: each directory has a list of files, directories, ... it contains (the directory index). This index always includes 2 entries: 1 pointing to the current directory, and one pointing to the parent directory. And it's important that they are there, because it makes path traversal independent from the program and moves the responsibility to the system, and ensures that all programs can traverse the path upwards in the same manner.

It's hardcoded. In the original UNIX way back in the 70's I think they were just links added manually, but they quickly became an operating system feature.

They're not just a UNIX thing either -- DOS/Windows shells have always had them too.

And really, you need them. It'd be a pain having to type the absolute path for everything all the time. (Windows CE has no concept of 'current directory' at all, and is indeed a pain.)

So when you're doing

rm -Rf ./

what you're really doing is

rm -Rf /path/to/current/directory

Which UNIX will actually let you do, even when you're sitting inside it! The directory won't vanish for real until you stop using it, but nobody else will be able to find it anymore, and once you leave it it will really be gone.

1 Like

Thanks all for your help.. that was really helpful..