0
0
Linux CLIscripting~5 mins

Inodes concept in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
Inodes are like ID cards for files on a Linux system. They store information about files except their names, helping the system find and manage files efficiently.
When you want to understand why you cannot create more files even if disk space is available.
When you need to check file metadata like permissions, ownership, and timestamps.
When troubleshooting file system issues related to file limits.
When you want to see how many files are on a disk or partition.
When you want to find the inode number of a specific file for advanced file operations.
Commands
This command lists files in the current directory along with their inode numbers, showing the unique ID for each file.
Terminal
ls -i
Expected OutputExpected
123456 file1.txt 123457 file2.txt 123458 script.sh
-i - Show inode number of each file
This command shows inode usage and availability on all mounted filesystems, helping you see if you are running out of inodes.
Terminal
df -i
Expected OutputExpected
Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sda1 6553600 123456 6420144 2% / tmpfs 1024000 512 1023488 1% /run
-i - Display inode information instead of disk space
This command shows detailed information about the file 'file1.txt', including its inode number, permissions, owner, and timestamps.
Terminal
stat file1.txt
Expected OutputExpected
File: file1.txt Size: 1024 Blocks: 8 IO Block: 4096 regular file Device: 802h/2050d Inode: 123456 Links: 1 Access: 2024-06-01 10:00:00.000000000 +0000 Modify: 2024-06-01 09:50:00.000000000 +0000 Change: 2024-06-01 09:55:00.000000000 +0000 Birth: -
Key Concept

If you remember nothing else from this pattern, remember: an inode is the unique identifier that stores all metadata about a file except its name.

Common Mistakes
Trying to find file names using inode numbers directly without tools.
Inodes do not store file names, so you cannot get a file name from an inode without searching the filesystem.
Use commands like 'find / -inum INODE_NUMBER' to locate the file name from an inode.
Confusing inode exhaustion with disk space exhaustion.
You may have free disk space but no free inodes, preventing new files from being created.
Check inode usage with 'df -i' to diagnose inode exhaustion separately from disk space.
Summary
Use 'ls -i' to see inode numbers of files in a directory.
Use 'df -i' to check inode usage on filesystems.
Use 'stat filename' to view detailed inode metadata for a file.