Disk Usage in Linux Console: Using df and du Commands

Learn how to analyze disk usage in Linux using df and du commands. Ten examples for efficient storage management and optimization.

Monitoring disk usage is crucial for effective storage management in Linux systems. This article provides a comprehensive guide on using the df and du commands in the Linux console to display disk usage information. Learn how to analyze file system utilization, identify space-consuming directories, and optimize storage resources efficiently.

Here are some examples of using df and du commands for disk usage analysis in Linux:

1. Display overall disk space usage:

df -h

2. Show disk space usage for a specific directory:

du -h /path/to/directory

3. Sort and display disk usage for directories in ascending order:

du -h --max-depth=1 | sort -h

4. Show total disk usage summary for a directory:

du -sh /path/to/directory

5. Display disk space usage for each file in a directory:

du -ah /path/to/directory

6. View disk space usage for a specific file:

du -h /path/to/file

7. Show the largest directories in a specific location:

du -h --max-depth=1 /path/to/location | sort -hr

8. Monitor disk usage in real-time:

watch -n 1 df -h

9. List files and directories in a directory, sorted by size:

ls -lhS /path/to/directory

10. Display disk usage in human-readable format with 1K block size:

du -h --block-size=1K /path/to/directory

By mastering these df and du commands, you can efficiently analyze disk usage, identify storage bottlenecks, and optimize your Linux system's storage management.

Remember to consult the command's manual pages or additional online resources for more options and detailed usage instructions.