Inode number changes for a file in Redhat Linux


 
Thread Tools Search this Thread
Operating Systems Linux Inode number changes for a file in Redhat Linux
# 1  
Old 10-09-2014
Inode number changes for a file in Redhat Linux

Hi,

I have created a file a.txt in Redhat Linux.

Inode number for a file changes every time i update the file using vi editor , gedit etc.

Is there any setting that can be made , such that inode number never changes as that is supposed to be the expected behavior?

Or if we cannot restrict the inode number change , is there a way to identify the file uniquely as inode number does.

I need a way to differentiate between a.txt that is modified and a.txt that was created after renaming the earlier a..txt to a.txt.1

Kindly reply

Thanks in Advance.
Sriram

Last edited by srirammanohar; 10-09-2014 at 09:50 AM..
# 2  
Old 10-09-2014
Hi,

You can look at the Inode detail using the "stat" command as follows;

Code:
[root@ekbit13 bin]# stat a
  File: `a'
  Size: 32        	Blocks: 8          IO Block: 4096   regular file
Device: 811h/2065d	Inode: 2097756     Links: 1
Access: (0644/-rw-r--r--)  Uid: (  505/ sc386dm)   Gid: (  500/ sc386dm)
Access: 2014-10-07 09:54:27.132865927 +0100
Modify: 2014-09-10 16:24:31.432147640 +0100
Change: 2014-09-10 16:24:31.432147640 +0100

Regards

Dave
# 3  
Old 10-09-2014
Yes I have used the stat command to determine Inode.
The problem is when I modify the file, the inode changes , even though it is supposed to be the same.


Code:
bash-2.05$ stat c.txt
  File: `c.txt'
  Size: 92807           Blocks: 192        IO Block: 4096   regular file
Device: ca02h/51714d    Inode: 35225883    Links: 1
Access: (0666/-rw-rw-rw-)  Uid: (559587/    srmm)   Gid: ( 8500/     dba)
Access: 2014-10-08 22:52:27.000000000 -0700
Modify: 2014-10-08 22:34:42.000000000 -0700
Change: 2014-10-08 22:34:42.000000000 -0700
bash-2.05$ gedit c.txt
bash-2.05$ stat c.txt
  File: `c.txt'
  Size: 92813           Blocks: 192        IO Block: 4096   regular file
Device: ca02h/51714d    Inode: 35225885    Links: 1
Access: (0666/-rw-rw-rw-)  Uid: (559587/    srmm)   Gid: ( 8500/     dba)
Access: 2014-10-08 22:53:11.000000000 -0700
Modify: 2014-10-08 22:53:11.000000000 -0700
Change: 2014-10-08 22:53:11.000000000 -0700


Last edited by vbe; 10-09-2014 at 05:17 AM..
# 4  
Old 10-09-2014
Quote:
Originally Posted by srirammanohar
Hi,

I have created a file a.txt in Redhat Linux.

Inode number for a file get changes every time i update the file using vi editor , gedit etc.

Is there any setting that can be made , such that inode number never gets changed?

Or if we cannot restrict from inode number getting changed , is there any way to identify the file uniquely as inode number does.

I need a way to differentiate between a.txt that is modified and a.txt that was created after renaming the earlier a..txt to a.txt.1

Kindly reply

Thanks in Advance.
Sriram
If there are multiple links to a file, vi file should not change the i-node number. If there is only one link to a file and you make any changes to the file using vi, it is more efficient to rename the temp file to the final resting place rather than copy the temp file onto the original file and then remove the temp file.

Why do you care if the i-node number changes? Why isn't the file's name (a.txt) sufficient for identifying the file?

(Note that ls -i and ls -li will also give you the i-node number even on systems that don't have the stat utility.)
# 5  
Old 10-09-2014
Hey thanks,
I need a way to uniquely determine if a log file is rotated/rolled up or not.
In case it is rotated, the original log file (a.log) will be renamed to a.log.1 and a new a.log is created. So the new a.log will have a different inode no. This way I can determine if a log file has been rotated or not. However ,if the inode no changes for every modification I cannot check if a file is rotated/rolled up or not.
Can you think of some other file attribute that will help me uniquely identify this?
Is there a way to keep the inode constant?
# 6  
Old 10-09-2014
This is just a wild guess - I can not reproduce your findings on my systems and I have no gedit available.
vi usually creates a swap file which you work on instead of the original file. Maybe your vi-implementation replaces the original file with the swap file. vim 7.3 offers the -n flag to disallow the creation of the swap file (:set uc=0 should do the same).
# 7  
Old 10-09-2014
Though this problem reproduces with VI and gedit, this happens when we perform file handling operations using java C and perl. In these cases, the files are modified by the program. Do you think the issue is more related to an OS ?
So say, a java program creates and modifies a file, with each modification the inode changes. This happens not just in my machine but in multiple machines. Can we work around this behavior somehow?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Retreive deleted file name if you having inode number

Some one please help me to find deleted file name, if I am having inode number in Solaris without using any 3rd party tool. Thanks :) (3 Replies)
Discussion started by: aksijain
3 Replies

2. Red Hat

Inode number changes for a file in Redhat Linux

Hi, I have created a file abc.log in Redhat Linux. Inode number for a file get changes every time i update the file using vi editor. Is there any setting that can be made , such that inode number never gets changed? Or if we cannot restrict from inode number getting changed , is... (9 Replies)
Discussion started by: raghu.amilineni
9 Replies

3. Shell Programming and Scripting

Modifying a file without changing inode number

Hi all, I am struggling to change the content of a file without changing the inode number. The exact issue is as below. I have a file name test.bak which has 100 lines of text. I am trying to to delete the first 90 lines of the text in the file. I know that using sed/awk/head/tail I can... (3 Replies)
Discussion started by: sathishkmrv
3 Replies

4. AIX

How to get the filename of which has been deleted if I know the inode number?

How to get the filename of which has been deleted if I know the inode number. i can use the command "istat" to get the inode number of the file. # istat /proc//fd/x If this file has been deleted,but the process of this file has not been closed and handle has not been released ,so this... (3 Replies)
Discussion started by: JoyOnLine
3 Replies

5. Solaris

How to increase or decrease inode number of the particular UFS filesystem

Hi Gurus I want to know the command & tips regarding, how to increase or decrease inode number of the particular ufs filesystem. Is it possible to do it in a live/production environment. Regards (3 Replies)
Discussion started by: girish.batra
3 Replies

6. Filesystems, Disks and Memory

Recreating a deleted hardlink to a file if I know the inode number

At risk of twisting the rules to nearly the point of breaking (if you think this goes too far mods, I apologise and accept that this should be deleted), I'm hoping someone might be able to cast a little light on the following problem regarding hard links to files. ... (6 Replies)
Discussion started by: Smiling Dragon
6 Replies

7. UNIX for Dummies Questions & Answers

Number of Inode on a disk

How we can know number of inode present in my Disk including free and occupied. Is there any tool or program to know how much free inode are there in inode free list . (2 Replies)
Discussion started by: mr_deb
2 Replies

8. UNIX for Advanced & Expert Users

how to find out pathname from inode number

Hi all when I execute pmap command on one of my daemon process, I am able to see the following output. Address Kbytes RSS Anon Locked Mode Mapped File 00010000 40 40 - - r-x-- irs026bmd 00028000 56 56 16 - rwx-- irs026bmd 00036000... (3 Replies)
Discussion started by: axes
3 Replies

9. Filesystems, Disks and Memory

Inode number

as kernel keeps track of user activities on a file by its INODE number and I node table . what is the structure of Inode table. and where does this Inode table mapped into?user space or kernel space? is the Inode Number is fixed for a file till its deletion? thanks (1 Reply)
Discussion started by: compbug
1 Replies

10. UNIX for Dummies Questions & Answers

Directory Inode Number Not Unique

Hi, I know that inode for each file is unique, but is it the for the directory? So far I found different directories has the same inode nubmer when you do ls -i, could some one explain why? Thanks a lot. (9 Replies)
Discussion started by: nj302
9 Replies
Login or Register to Ask a Question