[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Why does linux change the inode number after editing the file?

Posted on 2011-09-21
7
Medium Priority
?
765 Views
Last Modified: 2012-05-12
Hello, I am wondering why does linux change the inode number after editing the file? if I open a text/conf file in linux and edit it then I find that it has changed the inode number. It does affect my application but it has made me curious.

Please let me know if someone can answer this behavior. Thanks!
0
Comment
Question by:beer9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 21

Expert Comment

by:Papertrip
ID: 36577913
Because file size, physical location on disk, ctime/mtime/atime are all stored in the inode, amongst other things of course.
0
 
LVL 80

Accepted Solution

by:
arnold earned 1000 total points
ID: 36577916
I might be that you have a mechanism that you are actually editing a copy rather than the real file such that when the transaction is complete, the original is deleted with the temporary copy modified is renamed.

do you have cvs/subversion on the system to keep track of file changes?
0
 
LVL 21

Expert Comment

by:Papertrip
ID: 36577939
I wanted to expand on the "other things" from my first answer.  Check out the man page for the stat() function.

struct stat {
    dev_t     st_dev;     /* ID of device containing file */
    ino_t     st_ino;     /* inode number */
    mode_t    st_mode;    /* protection */
    nlink_t   st_nlink;   /* number of hard links */
    uid_t     st_uid;     /* user ID of owner */
    gid_t     st_gid;     /* group ID of owner */
    dev_t     st_rdev;    /* device ID (if special file) */
    off_t     st_size;    /* total size, in bytes */
    blksize_t st_blksize; /* blocksize for filesystem I/O */
    blkcnt_t  st_blocks;  /* number of blocks allocated */
    time_t    st_atime;   /* time of last access */
    time_t    st_mtime;   /* time of last modification */
    time_t    st_ctime;   /* time of last status change */
};
0
Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

 
LVL 21

Expert Comment

by:Papertrip
ID: 36578003
Found an explanation that is less technical.  I've never seen it written out so nicely :)


The inode contains all the information necessary for a process to access the file, such as file ownership, access rights, file size, time of last access or modification, and the location of the file’s data on disk. Since a file’s data is spread across disk blocks, the inode contains a “table of contents” to help locate this data. Good analogy.

It is important to note the distinction between changing the contents of an inode and changing the contents of a file. The contents of a file only change on a write operation.

The contents of an inode change when

    (1) the contents of the corresponding file change (because when you update the file contents, you change the time of last modification. This is what you can search for with the find command using the -mtime flag, but I digress), or
    (2) when its owner (e.g. using chown), permissions (chmod or chgrp), or any of the other information that is maintained as part of the inode changes.

    Thus, changing the contents of a file automatically implies a change to the inode, whereas a change to the inode does not imply that the contents of the file have changed.
0
 
LVL 12

Assisted Solution

by:hfraser
hfraser earned 1000 total points
ID: 36578055
"vi" manages your editting changes by keeping a memory-resident copy of the file along with a ".swp" file that contains all the changes, leaving the original file intact. The combination of the original and the .swp file allow the modified file to be re-created if there are any problems either during the editting session or during the save of the modified file. If the original file were overwritten during the save to preserve the inode, and a problem occured during the save, it would not be possible to re-create the editted file using the original file (now corrupted) plus changes. Instead, a new file is created, and only after that is successul are the original and .swp files deleted.
0
 
LVL 21

Expert Comment

by:Papertrip
ID: 36578078
Apologies I misread your original question and got stuck on my lil tangent.  At least you know all about inodes now though :p

arnold and hfraser are probably on the right track.
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36578299
I agree that it's likely the file is being copied.  If you need further assistance, it would help to know which editor you are using.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question