//THE ACADEMY IS GROWING DAILY. CHECK OUT THE FIELD NOTES FROM TECHS HERE AT THE ACADEMY
>_DAEMONCORE // ACADEMY
← FIELD NOTES

Understanding inodes and file management in Unix filesystems

2026.10.04//12 MIN READlinuxfilesystemsdigital-forensicsfundamentals

// Inodes: The Core of Unix Filesystems

In Unix-like operating systems, every file is represented by an inode (index node). Each inode contains metadata about a file, which includes its size, ownership, permissions, and pointers to the actual data blocks where the file's contents reside on the disk. Understanding inodes is crucial for effective file management, especially when dealing with deletion and recovery operations.

// Structure of an Inode

An inode does not contain the filename or the actual data of the file. Instead, it holds:

  • File type: Regular file, directory, symlink, etc.
  • Permissions: Read, write, execute permissions for user, group, and others.
  • Owner: User ID (UID) of the file's owner.
  • Group: Group ID (GID) of the file's group.
  • Size: Total size of the file in bytes.
  • Timestamps: Creation, modification, and last access times.
  • Data block pointers: Addresses of the blocks where the file data is stored.

A common way to inspect inodes is to use the ls command with -i flag:

ls -i filename

This command displays the inode number of filename. You can also check the inode information using the stat command:

stat filename

This will output detailed information about the file, including its inode number and all the metadata associated with it.

// File Deletion in Unix

When a file is deleted in Unix, the file's link is removed from the directory structure. However, the inode and its data blocks remain intact until they are overwritten by new data. This is essential for recovery processes. The structure of the file system allows for a potential restoration of the file as long as its inode is not reused.

To illustrate, when you remove a file using:

rm filename

You're effectively removing the directory entry pointing to the inode, but the inode itself, along with its data blocks, remains intact until the space is needed again.

// Recovering Deleted Files

There are several tools available for recovering files in Unix-like systems. One popular tool is extundelete, which can recover deleted files from ext3 or ext4 filesystems. The recovery process typically requires the filesystem to be unmounted to prevent further data overwriting.

1. First, unmount the filesystem:

   umount /dev/sdX1

2. Then, run extundelete on the unmounted partition:

   extundelete /dev/sdX1 --restore-file path/to/deleted/file

Replace path/to/deleted/file with the actual path of the file you want to recover.

3. The recovered file will be placed in a directory named RECOVERED_FILES within the current working directory.

Mistakes to Avoid

  • Not unmounting the filesystem: Attempting to recover files while the filesystem is mounted can lead to data overwriting, making recovery impossible.
  • Using rm -rf without caution: This command can permanently delete files without a trace. Always double-check the path before execution.

// Defensive Implications

Understanding how inodes and file management work is not only beneficial for recovery but also for securing your systems. Regular backups are essential to minimize data loss. Tools like rsync can be useful for this:

rsync -av --delete /source/directory/ /backup/directory/

This command synchronizes the contents from the source to the backup directory, providing a snapshot of your files.

// Checklist for File Management and Recovery

  • [ ] Understand the inode structure.
  • [ ] Use rm with caution; consider mv to a temporary directory instead.
  • [ ] Regularly back up important data.
  • [ ] Familiarize yourself with recovery tools like extundelete and photorec.
  • [ ] Always unmount the filesystem before recovery attempts.

The DaemonCore Academy curriculum is highly accessible, with no recurring subscriptions, providing hands-on experience in these techniques. Remember to practice these techniques in a disposable range you own.

--- // FIELDOPS REPORT AUTHORIZED BY: Bruce H. //