38.4k views
3 votes
When mv f1 f2 is executed, which file's inode is freed?

1) f1
2) f2
3) new inode will be used

User Gidzior
by
8.4k points

2 Answers

1 vote

Final answer:

When 'mv f1 f2' is executed, 'f1' is renamed to 'f2', and if 'f2' exists, it is overwritten. The inode of 'f1' remains, while the original 'f2' inode is freed.

Step-by-step explanation:

When the command mv f1 f2 is executed in a Unix-based operating system, it moves the content of file f1 to file f2. If file f2 already exists, it will be overwritten. The inode of file f1 is not freed; instead, the same inode now points to the filename f2. No new inode is created unless the files are on different file systems. When file f2 is overwritten, the system will free up its inode if no other hard link is pointing to the same inode.

User Joraff
by
8.0k points
2 votes

Final answer:

When 'mv f1 f2' is executed, if 'f2' exists, its inode is freed; otherwise, 'f1's inode is simply renamed to 'f2' and no inodes are freed.

Step-by-step explanation:

When the command mv f1 f2 is executed in a Unix-like operating system, the inode that gets freed depends on whether f2 already exists. If f2 exists, its inode is freed, meaning the inode that previously belonged to f2 is no longer used because f2 now points to f1's data. If f2 does not exist prior to the move, no inode is freed; instead, the directory entry for f1 is simply updated to the new name f2, and no new inode is created. In both cases, the inode originally associated with f1 remains intact, retaining all of f1's metadata and pointing to the same data blocks on the storage device.

User Red Riding Hood
by
8.9k points