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
# 8  
Old 10-09-2014
What kind of filesystem do this files reside on?
# 9  
Old 10-09-2014
they are Unix file systems , if that is what you mean?
# 10  
Old 10-09-2014
Hi,

I think what is meant is what is the filesystem type, ext2, ext3, ext4, jfs, zfs, ufs, adfs etc.

Anyway, in answer to your original question, "Why does the Inode number change." It is likely that this is due to the editor, as they quite often work with "shadow copies" of the file you are editing, and the new copy replaces the original file.

Regards

Dave
# 11  
Old 10-09-2014
oh ok. It is UFS
# 12  
Old 10-09-2014
Hi,

I don't use Gedit, however if you open a file in gedit and while it is open have a look in the directory to see if there are other copies of the file as follows;
Code:
[root@ekbit13 bin]# ls -l sergen*
-rwxr-xr-x. 1 sc386dm sc386dm 12800 Nov 18  2013 sergen.scr
-rwxr-xr-x. 1 sc386dm sc386dm 13174 Nov  5  2013 sergen.scr~
[root@ekbit13 bin]# stat sergen.scr
  File: `sergen.scr'
  Size: 12800     	Blocks: 32         IO Block: 4096   regular file
Device: 811h/2065d	Inode: 2099809     Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (  505/ sc386dm)   Gid: (  500/ sc386dm)
Access: 2014-10-09 10:21:48.695567634 +0100
Modify: 2014-10-09 10:21:48.701567649 +0100
Change: 2014-10-09 10:21:48.721567699 +0100
[root@ekbit13 bin]# stat sergen.scr~
  File: `sergen.scr~'
  Size: 13174     	Blocks: 32         IO Block: 4096   regular file
Device: 811h/2065d	Inode: 2098503     Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (  505/ sc386dm)   Gid: (  500/ sc386dm)
Access: 2014-10-07 09:54:27.133865925 +0100
Modify: 2013-11-05 21:46:48.371733236 +0000
Change: 2013-11-05 21:46:48.371733236 +0000
[root@ekbit13 bin]# vim sergen.scr
[root@ekbit13 bin]# stat sergen.scr
  File: `sergen.scr'
  Size: 12800     	Blocks: 32         IO Block: 4096   regular file
Device: 811h/2065d	Inode: 2099808     Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (  505/ sc386dm)   Gid: (  500/ sc386dm)
Access: 2014-10-09 10:22:51.895723445 +0100
Modify: 2014-10-09 10:22:51.895723445 +0100
Change: 2014-10-09 10:22:51.919723502 +0100
[root@ekbit13 bin]# vim sergen.scr
[root@ekbit13 bin]# stat sergen.scr~
  File: `sergen.scr~'
  Size: 13174     	Blocks: 32         IO Block: 4096   regular file
Device: 811h/2065d	Inode: 2098503     Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (  505/ sc386dm)   Gid: (  500/ sc386dm)
Access: 2014-10-07 09:54:27.133865925 +0100
Modify: 2013-11-05 21:46:48.371733236 +0000
Change: 2013-11-05 21:46:48.371733236 +0000
[root@ekbit13 bin]#

As you can see the Inode numbers have changed, below is an actual example using the Bluefish editor.

Code:
[~/test] 
(10:34:01)-(sc386dm)-(685)-> touch testfile.txt

[~/test] 
(10:34:14)-(sc386dm)-(686)-> stat testfile.txt
  File: `testfile.txt'
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: 811h/2065d	Inode: 2098216     Links: 1
Access: (0664/-rw-rw-r--)  Uid: (  505/ sc386dm)   Gid: (  500/ sc386dm)
Access: 2014-10-09 10:34:14.713010608 +0100
Modify: 2014-10-09 10:34:14.713010608 +0100
Change: 2014-10-09 10:34:14.713010608 +0100

[~/test] 
(10:34:22)-(sc386dm)-(687)-> ls -latr
total 12
drwx------. 47 sc386dm sc386dm 4096 Oct  9 10:31 ..
-rw-rw-r--   1 sc386dm sc386dm    0 Oct  9 10:34 testfile.txt~
-rw-rw-r--   1 sc386dm sc386dm    6 Oct  9 10:34 testfile.txt
drwxrwxr-x   2 sc386dm sc386dm 4096 Oct  9 10:34 .

[~/test] 
(10:35:01)-(sc386dm)-(688)-> stat testfile.txt
  File: `testfile.txt'
  Size: 6         	Blocks: 8          IO Block: 4096   regular file
Device: 811h/2065d	Inode: 2099835     Links: 1
Access: (0664/-rw-rw-r--)  Uid: (  505/ sc386dm)   Gid: (  500/ sc386dm)
Access: 2014-10-09 10:34:48.307144361 +0100
Modify: 2014-10-09 10:34:48.307144361 +0100
Change: 2014-10-09 10:34:48.324144444 +0100

[~/test] 
(10:35:13)-(sc386dm)-(689)-> stat testfile.txt~
  File: `testfile.txt~'
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: 811h/2065d	Inode: 2098216     Links: 1
Access: (0664/-rw-rw-r--)  Uid: (  505/ sc386dm)   Gid: (  500/ sc386dm)
Access: 2014-10-09 10:34:36.018083824 +0100
Modify: 2014-10-09 10:34:14.713010608 +0100
Change: 2014-10-09 10:34:48.324144444 +0100

[~/test] 
(10:35:27)-(sc386dm)-(690)->

Hope that this helps.

Regards

Dave

Last edited by gull04; 10-09-2014 at 06:37 AM.. Reason: More information and example.
# 13  
Old 10-09-2014
Modifying an existing file does not change the inode number. The code you're using rewrites the file to a new one, then rename()'s the new file with the old name.

How do you stop that? You don't do it.

If your log file inodes are changing, I'd say the problem is, "Who is editing the log files?" There's auditing to figure that out.
# 14  
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 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?
It means the file is being replaced by another file, not that the inode on the same file is "changing" somehow. Prevent the directory from being written to by the processes -- to prevent the moving, creation, and deletion of files -- will prevent the inode from "changing" -- by stopping these things from working. The file can still be overwritten.

If you want the inode to remain the same, don't use anything that replaces it. If you use stream commands to alter the file, don't edit "in place" or such -- redirect them to a temp file, then cat the new file over the original. To edit, copy to a temp file, edit the temp file, then cat the temp file over the original. I think this is what commands like crontab -e and visudo do.

Last edited by Corona688; 10-09-2014 at 01:04 PM..
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