Linux: Inodes – Soft/Hard Links

INODES

An inode is a datastructrure that is associated with objects in Linux. Each object in Linux is associated with an object. Inodes do not show us metadata (results of an ls -l command). The following are objects that inodes are associated with.

  • User/Group owner.
  • File permissions.
  • Access – Modification – Change – Deletion times
  • Size
  • Blocks
  • Number of hard/soft links
  • How to get object information for a file:

 

On your command prompt create a file and then run the stat command.

cd /tmp; touch file;
stat file

Output:

File: ‘file’
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 1fh/31d Inode: 1448926 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/gmastrokostas) Gid: ( 1000/gmastrokostas)
Access: 2013-06-30 14:43:32.997516030 -0400
Modify: 2013-06-30 14:43:32.997516030 -0400
Change: 2013-06-30 14:43:32.997516030 -0400
Birth: -

Some things to take note from the output above:

  • inode: 1448926
  • Links: 1
  • Access: Displays when a file was accessed (read/executed)
  • Modify: Displays when a file was modified (written).
  • Change: Displays when a file was changed (written or ownership change).

Soft Vs Hard Links
A hard link creates a file that is exactly the same as the original file. A change on the original file will be reflected to the file created as a hard link and the other way around. However, hard links cannot span on different filesystems and cannot refer to directories.
To create a hard link:

cd /tmp; touch file
ln file hard_link

A soft link creates a pointer (if you will) to the original file. You can create many symbolic links that point to the original file (inode). Softlinks can span on different filesystems. However softlinks are not being updated when changes occur to the original file.
To create a soft link:

cd /tmp/ touch file
ln -s file soft_link
Share Button

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload the CAPTCHA.