About nixCraft

Topics

Understanding UNIX / Linux filesystem Inodes

Posted by Vivek Gite [Last updated: December 2, 2007]

The inode (index node) is a fundamental concept in the Linux filesystem. Each object in the filesystem is represented by an inode. But what are the objects? Let us try to understand it in simple words. Each and every file under Linux (and UNIX) has following attributes:

=> File type (executable, block special etc)
=> Permissions (read, write etc)
=> Owner
=> Group
=> File Size
=> File access, change and modification time (remember UNIX or Linux never stores file creation time, this is favorite question asked in UNIX/Linux sys admin job interview)
=> File deletion time
=> Number of links (soft/hard)
=> Extended attribute such as append only or no one can delete file including root user (immutability)
=> Access Control List (ACLs)

All the above information stored in an inode. In short the inode identifies the file and its attributes (as above) . Each inode is identified by a unique inode number within the file system. Inode is also know as index number.

How do I see file inode number?

You can use ls -i command to see inode number of file
$ ls -i /etc/passwdOutput

32820 /etc/passwd

You can also use stat command to find out inode number and its attribute:
$ stat /etc/passwdOutput:

File: `/etc/passwd'
Size: 1988            Blocks: 8          IO Block: 4096   regular file
Device: 341h/833d       Inode: 32820       Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2005-11-10 01:26:01.000000000 +0530
Modify: 2005-10-27 13:26:56.000000000 +0530
Change: 2005-10-27 13:26:56.000000000 +0530

Inode application

So what is the practical application of inode number? Sure without an example no one like the concepts. Type the following commands:
$ cd /tmp
$ touch \"la*
$ ls -l

Now try to remove file "la*

You can't, to remove files having created with control characters or characters which are unable to be input on a keyboard or special character such as ?, * ^ etc. You have to use inode number to remove file. This is fourth part of "Understanding UNIX/Linux file system, continue reading rest of the Understanding Linux file system series (this is part IV):

Tell us how we're doing: Please answer a few questions about your experience to help us improve nixCraft.

You may also be interested in other helpful articles:

Discussion on This Article:

  1. makash Says:

    OT but was wondering are you from India?

    The timestamp is a give away

  2. nixcraft Says:

    Yup I’m from India :)

  3. Anonymous Says:

    hm, did I something wrong? I can remove the file with $ rm “la*

  4. Thomas Scott Says:

    Future is , no one will load
    executable code , only data and
    data will be parsed by kernel and
    typed , compresed , and added to
    a structure .
    This allows the OpSys to be tiny .
    because it eliminates the extra
    work the kernel had to do ,
    explaining to humans ….
    This obsoletes SU and makes it
    much easier to “control” a machine .
    Permissions are no longer necessary .
    Scratch lists stop all unauthorized
    acesses .
    This not new , these simple fixes
    have been around for 100’s of years ,
    Only computer s/w can change in
    minutes , and “pink slip” millions .

  5. aamod Says:

    Great blog…. Has a lot of correct info and I find it very useful….

  6. Riz Says:

    just to let you know…. that file once created can be removed in another way. using rm -i *. this is an interactive mode and asks you if want to delete each file in turn. so please correct as the above information you are providing is inaccurate.

  7. vivek Says:

    Riz,

    I’m aware of this command. A long time ago on NFS mounted system there was a file called 2001/05/11. and no UNIX / Linux command was able delete this file by name. Only method to delete such file is delete file by an inode number. Linux or UNIX never allows creating filename like 2001/05/11 but if you are using NFS from MAC OS or Windows then it is possible to create a such file.

    So above information is 100% accurate.

  8. Riz Says:

    vivek,

    i dont have a windows box to test this so i will take you word as gold, but it is nice to see an active posting community rather than one which is dead (which i normally find whilst search things like this)

    Riz.

  9. Anyeos Says:

    What strange but true I cannot create a dir or file with this commands:
    touch “10/11/2006″
    mkdir “10/11/2006″

    You can see what I’m using quotes to bypass the shell. But anyway I cannot create such file/dir.

    That is for some reason?
    I have other doubt (I don’t expect to be answered here): Why linux filesystem does not save “file creation time”? What is the reason?

    Bye

  10. ronald Says:

    It’s inaccurate to say that every file under Linux has the attributes that you listed … especially the extended attributes. All these attributes are properties of the filesystem, be it ext3, xfs, jfs etc. In particular, extended attributes apply to ext2/ext3

  11. prasanna kumar Says:

    hi friends,,
    plz i want some coomands in linux
    1)question: in linux basic commands are not working that u can do.
    example : ls
    pc displays command not found.
    2)question : i have 3 files. i want serach some words like kernel.all files are have kernel word so prints word as well as numbers with single line. using single command grep (or) sde command plz send syntax and example.

  12. Moneo Says:

    rm ‘”\la*’

    deleted it fine for me

  13. tarun Says:

    this is to aneyous according to my knowledge if u want to create a file say 10/11/2008 try this 10\11\2008 and for a directory also

  14. tarun Says:

    guys i have one question i couldnt find an answer to ..i will explain in steps what did i do
    from root user i did this:
    1. adduser tarun
    2. passwd tarun
    3. log in to a terminal with user tarun
    4. create a text file say “test1″ with “cat” and
    type some text in it,and save the file.
    5. now i did chmod 000 on the file.
    6. i opened “test1″ with vim editor. i try
    inserting some text in it i get a warning tht
    i might be changing a read only file,
    7. i save and exit the text inside “test1″
    forcefully using “wq!”
    8. now i do chmod 644 on “test1″and again open the file and write something in it and save it
    9. if do “cat test1″ i see only the last text i inserted after doing chmod 644 and not anything before …could’nt figure it out why the system did not append the text i had just written to the text i had written earlier

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , ,

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.