0

Since everything in Unix is a file, when we call "cd ." are we actually cding into the directory . ? Is it a protected symbolic reference to the parent directory of each directory?

DMAN
  • 13
  • 2
  • 1
    Both `.` and `..` are actual filename entries (inode number plus file name) in the directory pointing at the current directory and the parent directory respectively. They are not symbolic links; they are hard links. And every process has a current directory recorded by the kernel. That keeps a reference count on the directory inode so that things don't go too horribly wrong. – Jonathan Leffler Nov 21 '16 at 21:06
  • Please read http://stackoverflow.com/help/how-to-ask , http://stackoverflow.com/help/dont-ask , http://stackoverflow.com/help/mcve and take the [tour](http://stackoverflow.com/tour) before posting more Qs here. Good luck. – shellter Nov 21 '16 at 21:58

1 Answers1

2

Yes, everything in Unix, is a file. Like any directory, a file of any type, any device(speaker, keyboard,. etc.) and even a file-system itself, all act like a file for OS. In Unix every file has a inode attached with it, which contains the file metadata like info about permissions, size, time-stamps and most importantly file data block pointers which point to data block containing actual file data.

Hence each Directory(being a file) also has a inode. The content of the directory is the sequence of records. Each record has at least two fields which are filename and the inode number.

file1name  file1_inode_number

Exact structure of record depends on the filesystem implementation. So basically directory file contain a (record)entry corresponding to each file and immediate sub-directory inside it. In addition to that, Directory file also contain 2 more entries which are

.    :  mapped with self inode 
and 
..   :  mapped with parent's inode

so all over directory structure looks like

.          inode_number_of_self
..         inode_number_of_parent_dir
file1name  inode_number_of_file1
file2name  inode_number_of_file2
.
.
so on

So whenever you cd ./ or cd ../ OS is referring current or parent directory(respectively) relative to your current directory.

hrishi
  • 443
  • 2
  • 12