Monday, 20 April 2015

Introduction to INODE




Also known as Index Node, Basically it is a “database” of all file information except the file contents and the file name.

In a file system, inodes consist roughly of 1% of the total disk space, whether it is a whole storage unit (hard disk,thumb drive, etc.) or a partition on a storage unit.  The inode space is used to “track” the files stored on the hard disk. The inode entries store metadata about each file, directory or object, but only points to these structures rather than storing the data. Each entry is 128 bytes in size.

The metadata contained about each structure can include the following:

  • Inode number
  • Access Control List (ACL)
  • Extended attribute
  • Direct/indirect disk blocks
  • Number of blocks
  • File access, change and modification time
  • File deletion time
  • File generation number
  • File size
  • File type
  • Group
  • Number of links
  • Owner
  • Permissions
  • Status flags
  •  
Commands used in inode 

1)    
listing of an inode number in the current directory
     
      $ ls –i
        
2)
find inode of a particular file
      
      $ ls –i filename
      
     eg:
           
         anusree@anusree-Inspiron-5547:~$ ls -i anu.py
         2098226 anu.py

        
3)
If you want to know more information than the inode number use "stat" command

      $ stat filename

eg:

         anusree@anusree-Inspiron-5547:~$ stat anu.py
        File: ‘anu.py’
        Size: 12            Blocks: 8          IO Block: 4096   regular file
        Device: 807h/2055d    Inode: 2098226     Links: 1
        Access: (0664/-rw-rw-r--)  Uid: ( 1000/ anusree)   Gid: ( 1000/        anusree)
       Access: 2015-04-19 22:24:20.447109534 +0530
       Modify: 2015-03-28 20:35:07.033135271 +0530
       Change: 2015-03-28 20:35:07.033135271 +0530
       Birth: -

      Both case , ie, $ ls -i anu.py and $ stat anu.py the inode number are same, 1596223 


        inode number can only change if the file is moved.
If the file is moved to a different directory, the commands are executed   again, the inode numbers are different :


      anusree@anusree-Inspiron-5547:~/Pictures$ ls -i anu.py
     1597693 anu.py



     anusree@anusree-Inspiron-5547:~/Pictures$ stat anu.py
     File: ‘anu.py’
     Size: 13            Blocks: 8          IO Block: 4096   regular file
     Device: 807h/2055d    Inode: 1597693     Links: 1
     Access: (0664/-rw-rw-r--)  Uid: ( 1000/ anusree)   Gid: ( 1000/   anusree)
     Access: 2015-04-20 19:01:03.854447830 +0530
     Modify: 2015-02-27 00:16:13.387166000 +0530
     Change: 2015-04-20 19:01:03.750447825 +0530
     Birth: -

      Now the inode number is 2098226 rather than 1597693. 


4)
You can also delete a file using its inode. Command is given bellow

 anusree@anusree-Inspiron-5547:~/Pictures$ find . -inum 1597693 -exec rm  -fi {} \;
rm: remove regular file ‘./anu.py’? yes



5)
To find the inode numbers of the directories, you can use the command “tree -a -L 1 --inodes / “. Output is given bellow:


anusree@anusree-Inspiron-5547:~/Pictures$ tree -a -L 1 --inodes /
/
|-- [1048577]  bin
|-- [11796481]  boot
|-- [13893633]  cdrom
|-- [   1025]  dev
|-- [11010049]  etc
|-- [1572865]  home
|-- [11796763]  initrd.img -> boot/initrd.img-3.16.0-30-generic
|-- [5242881]  lib
|-- [7864321]  lib64
|-- [     11]  lost+found
|-- [3145729]  media
|-- [18612225]  mnt
|-- [3932161]  opt
|-- [      1]  proc
|-- [2359297]  root
|-- [   1117]  run
|-- [19398657]  sbin
|-- [14942209]  srv
|-- [      1]  sys
|-- [12320769]  tmp
|-- [8650753]  usr
|-- [ 262145]  var
`-- [11796491]  vmlinuz -> boot/vmlinuz-3.16.0-30-generic

21 directories, 2 files

 

 (inode number for the specified directory in the brackets)


6)

To see files and subdirectories within a specific directory with its inode use the command ls -i directory

eg:
 find files and subdirectories of the directory Pictures

anusree@anusree-Inspiron-5547:~$ ls -i Pictures/
1591086 button_handler.png          

1591082 pipinstall.png                           
1589673 Screenshot from 2015-03-12 16:19:10.png
1594837 chrome_instaling error.png  

1587504 psc_last_grade_servents.png              
1589674 Screenshot from 2015-03-12 16:23:02.png
1587565 evnt.png                    

1591081 pygame.png                               
1574568 Screenshot from 2015-03-17 21:32:24.png
1580822 func.png                    

1575824 Screenshot from 2015-03-01 21:19:45.png  
1576883 Screenshot from 2015-04-01 21:43:11.png
1591254 mbox.png                    

1577519 Screenshot from 2015-03-10 15:05:56.png  
1595990 simplegui.png
1577152 mk_cron.png                 

1588832 Screenshot from 2015-03-12 12:03:21.png  
1580851 ss.png
1580268 mk_dirls.png                

1589516 Screenshot from 2015-03-12 15:23:00.png  
1596540 stepbyprocessofevet.png
1576825 mk_dir.png                  

1589671 Screenshot from 2015-03-12 15:24:42.png  
2098178 Wallpapers
1580383 mk_mode.png                 

1589670 Screenshot from 2015-03-12 15:25:52.png
1573185 pic                         

1589672 Screenshot from 2015-03-12 16:13:52.png