Bird
Raised Fist0
Linux CLIscripting~5 mins

Inodes concept in Linux CLI - Commands & Configuration

Choose your learning style10 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.

Practice

(1/5)
1. What does an inode in a Linux file system primarily store?
easy
A. The path to the file's location
B. The file name and its extension
C. Metadata about a file like permissions and size
D. The content of the file

Solution

  1. Step 1: Understand inode purpose

    An inode stores metadata such as file permissions, ownership, size, and timestamps, but not the file name.
  2. Step 2: Differentiate inode from file name storage

    The file name is stored separately in directory entries, not in the inode itself.
  3. Final Answer:

    Metadata about a file like permissions and size -> Option C
  4. Quick Check:

    Inode = Metadata [OK]
Hint: Inodes store file info, not names or content [OK]
Common Mistakes:
  • Thinking inode stores file names
  • Confusing inode with file content
  • Assuming inode stores file path
2. Which command correctly shows the inode number of files in a directory?
easy
A. ls -i
B. ls -l
C. ls -a
D. ls -h

Solution

  1. Step 1: Recall ls command options

    The ls -i command lists files with their inode numbers.
  2. Step 2: Verify other options

    ls -l shows detailed info without inode, ls -a shows hidden files, ls -h shows sizes in human-readable form.
  3. Final Answer:

    ls -i -> Option A
  4. Quick Check:

    ls -i = inode numbers [OK]
Hint: Use ls -i to see inode numbers quickly [OK]
Common Mistakes:
  • Using ls -l expecting inode numbers
  • Confusing ls -a with inode display
  • Trying ls -h for inode info
3. Given the output of ls -i shows two files with the same inode number, what does this indicate?
medium
A. The files are hard links pointing to the same data
B. The files have identical names
C. The files are located in different directories
D. The files are symbolic links

Solution

  1. Step 1: Understand inode sharing

    Two files with the same inode number mean they share the same data on disk, which happens with hard links.
  2. Step 2: Differentiate link types

    Symbolic links have different inodes; identical names or directories don't affect inode numbers.
  3. Final Answer:

    The files are hard links pointing to the same data -> Option A
  4. Quick Check:

    Same inode = hard links [OK]
Hint: Same inode means hard links share data [OK]
Common Mistakes:
  • Confusing symbolic links with hard links
  • Assuming same inode means same name
  • Ignoring inode uniqueness
4. You run ls -i but get an error: ls: invalid option -- 'i'. What is the likely cause?
medium
A. Not having permission to list files
B. Using a non-Linux system where ls lacks -i option
C. Typing the command incorrectly as ls -l
D. The directory is empty

Solution

  1. Step 1: Analyze error message

    The error says invalid option -- 'i', meaning the ls command does not recognize -i.
  2. Step 2: Identify environment cause

    This often happens on non-Linux systems (like some Unix variants) where ls lacks the -i option.
  3. Final Answer:

    Using a non-Linux system where ls lacks -i option -> Option B
  4. Quick Check:

    Invalid option = unsupported ls -i [OK]
Hint: Check OS if ls -i option fails [OK]
Common Mistakes:
  • Assuming typo in command
  • Thinking permission causes option error
  • Assuming empty directory causes option error
5. You want to find all files in a directory that share the same inode number (hard links). Which command pipeline helps you identify these files?
hard
A. find . -type l
B. ls -i | sort | uniq -d
C. ls -l | grep '^d'
D. ls -i | cut -d' ' -f1 | sort | uniq -d

Solution

  1. Step 1: Extract inode numbers from ls -i output

    The inode number is the first field in ls -i output, so use cut -d' ' -f1 to get it.
  2. Step 2: Find duplicate inode numbers

    Sorting and using uniq -d lists inode numbers that appear more than once, indicating hard links.
  3. Final Answer:

    ls -i | cut -d' ' -f1 | sort | uniq -d -> Option D
  4. Quick Check:

    Duplicate inodes = hard links [OK]
Hint: Extract inode field then find duplicates [OK]
Common Mistakes:
  • Using uniq -d without extracting inode field
  • Confusing symbolic links with hard links
  • Using find for symbolic links instead
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard