5. How do you check the disk space usage on a Linux system?

Basic

5. How do you check the disk space usage on a Linux system?

Overview

Understanding how to check disk space usage on a Linux system is crucial for both system administration and development tasks. It helps in managing resources efficiently, ensuring adequate space for operations, and troubleshooting issues related to disk space.

Key Concepts

  • Disk Usage (du) Command: Checks the space used by files and directories.
  • Disk Free (df) Command: Shows available disk space on file systems.
  • Inodes: Data structures on a filesystem that store information about files and directories.

Common Interview Questions

Basic Level

  1. How do you check the total disk space and usage on your Linux system?
  2. What is the command to find the disk usage of a specific directory?

Intermediate Level

  1. How can you display disk usage in a human-readable format?

Advanced Level

  1. How do you find the inode usage of the file systems on your Linux system?

Detailed Answers

1. How do you check the total disk space and usage on your Linux system?

Answer: To check the total disk space and usage on a Linux system, the df command is used. It displays the amount of disk space available on the file system containing each file name argument.

Key Points:
- df reports the amount of disk space used and available on file systems.
- By default, df displays space in 1K blocks.
- Using the -h option with df makes the output more readable, showing sizes in KB, MB, or GB.

Example:

// Using df to check disk space in human-readable format
df -h

2. What is the command to find the disk usage of a specific directory?

Answer: To find the disk usage of a specific directory, the du command is used. It summarizes disk usage of the set of files and directories.

Key Points:
- du shows the disk space used by a directory or file.
- The -h option makes the output human-readable.
- The -s option provides a summary for each argument.

Example:

// Using du to check disk usage of a specific directory in a readable format
du -sh /path/to/directory

3. How can you display disk usage in a human-readable format?

Answer: Both du and df commands can display disk usage in a human-readable format using the -h option. It automatically scales units to KB, MB, GB, etc., for easier comprehension.

Key Points:
- The -h option is available for both du and df.
- It helps in quickly understanding the size of files or available space.
- Useful for both system administrators and developers for quick checks.

Example:

// Displaying human-readable disk usage for files and free space
df -h       // For disk free space
du -h /path/to/directory  // For disk usage of a directory

4. How do you find the inode usage of the file systems on your Linux system?

Answer: The df command with the -i option can be used to display inode usage information for the file system.

Key Points:
- Inodes store essential information about files and directories.
- Running out of inodes indicates that no new files can be created.
- Monitoring inode usage is crucial for maintaining system health.

Example:

// Checking inode usage on all mounted file systems
df -i

This guide provides a foundational understanding of checking disk space and usage on Linux systems, covering basic commands and their usage.