Disk Usage with du and df
Monitoring disk usage is a critical task for maintaining a healthy Linux system. Over time, log files, caches, and user data can accumulate, consuming valuable disk space. If you do not keep track of available space, you risk running out of storage, which can lead to failed system operations or data loss. To avoid these issues, you need reliable tools to analyze and manage disk usage effectively.
# Summarize disk usage for a directory in human-readable format
du -h /var/log
# Limit output to one level deep (top-level subdirectories)
du -h --max-depth=1 /home/username
# Show disk usage for a single file
du -h /etc/passwd
The du command displays the amount of disk space used by files and directories. When you run du -h, the -h flag makes the output human-readable by using units like K (kilobytes), M (megabytes), and G (gigabytes). The --max-depth option allows you to control how deep du traverses into subdirectories, making it easier to get a summary view at different directory levels. Each line of the du output shows the size followed by the corresponding directory or file, helping you identify which locations consume the most space.
- Running
duon directories with restricted permissions might produce errors or incomplete results; - Hidden files and directories are included by default, which can sometimes lead to surprises in reported usage;
- Disk usage reported by
dumay not matchdfif files are open and deleted but still held by running processes.
- By default,
dureports the size of the link file itself, not the target; - Use the
-Loption to follow symlinks and report the size of the target files or directories; - Be cautious with
-Las it may result in counting the same data multiple times if symlinks point to the same location.
# Show disk space usage for all mounted filesystems in human-readable format
df -h
# Display filesystem type along with usage
df -hT
# Check usage for a specific filesystem or mount point
df -h /home
While du provides detailed information about the space used by specific files and directories, the df command offers an overview of disk space usage at the filesystem level. df -h shows the total, used, and available space for each mounted filesystem, making it easy to spot full or nearly full partitions. By combining du and df, you can first identify a full filesystem with df, then use du to drill down into which directories or files are consuming the most space. This approach helps you efficiently diagnose and resolve storage bottlenecks.
¡Gracias por tus comentarios!
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla
Can you explain the difference between `du` and `df` in more detail?
What are some common scenarios where I should use `du` versus `df`?
Are there any other useful options or flags for these commands?
Genial!
Completion tasa mejorada a 8.33
Disk Usage with du and df
Desliza para mostrar el menú
Monitoring disk usage is a critical task for maintaining a healthy Linux system. Over time, log files, caches, and user data can accumulate, consuming valuable disk space. If you do not keep track of available space, you risk running out of storage, which can lead to failed system operations or data loss. To avoid these issues, you need reliable tools to analyze and manage disk usage effectively.
# Summarize disk usage for a directory in human-readable format
du -h /var/log
# Limit output to one level deep (top-level subdirectories)
du -h --max-depth=1 /home/username
# Show disk usage for a single file
du -h /etc/passwd
The du command displays the amount of disk space used by files and directories. When you run du -h, the -h flag makes the output human-readable by using units like K (kilobytes), M (megabytes), and G (gigabytes). The --max-depth option allows you to control how deep du traverses into subdirectories, making it easier to get a summary view at different directory levels. Each line of the du output shows the size followed by the corresponding directory or file, helping you identify which locations consume the most space.
- Running
duon directories with restricted permissions might produce errors or incomplete results; - Hidden files and directories are included by default, which can sometimes lead to surprises in reported usage;
- Disk usage reported by
dumay not matchdfif files are open and deleted but still held by running processes.
- By default,
dureports the size of the link file itself, not the target; - Use the
-Loption to follow symlinks and report the size of the target files or directories; - Be cautious with
-Las it may result in counting the same data multiple times if symlinks point to the same location.
# Show disk space usage for all mounted filesystems in human-readable format
df -h
# Display filesystem type along with usage
df -hT
# Check usage for a specific filesystem or mount point
df -h /home
While du provides detailed information about the space used by specific files and directories, the df command offers an overview of disk space usage at the filesystem level. df -h shows the total, used, and available space for each mounted filesystem, making it easy to spot full or nearly full partitions. By combining du and df, you can first identify a full filesystem with df, then use du to drill down into which directories or files are consuming the most space. This approach helps you efficiently diagnose and resolve storage bottlenecks.
¡Gracias por tus comentarios!