Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does recreating a file reuse the previous inode? [closed]

Tags:

linux

I have a file a.txt.

If I delete the file and create an empty file with a.txt at the same location, will that influence the inode details of old file? or will a new inode will get created?

like image 201
Sai Koti Avatar asked Aug 30 '25 17:08

Sai Koti


1 Answers

It depends on your filesystem...

On ext4 I see the following: (inode reuse)

$ touch a.txt
$ stat -c%i a.txt
1316644

$ rm a.txt

$ touch a.txt
$ stat -c%i a.txt
1316644

On ZFS I see the following: (new inode assigned)

$ touch a.txt
$ stat -c%i a.txt
15585

$ rm a.txt

$ touch a.txt
$ stat -c%i a.txt
15586

stat -c%i ${FILENAME} will show the inode for the given file.

Note that inodes are not typically created/destroyed, but rather exist in perpetuity and are used to either record file information or are marked as "unused".


Note also, that on an active system you cannot place any guarantee on the same inode being reused, as it may be used by another file between your deletion and creation. i.e: the delete/create operation is not atomic.

On ext4:

$ touch a.txt
$ stat -c%i a.txt
1316644

$ rm a.txt

$ touch b.txt
$ stat -c%i b.txt
1316644

$ touch a.txt
$ stat -c%i a.txt
1316645
like image 98
Attie Avatar answered Sep 02 '25 14:09

Attie