Understanding File and Partition Sizes in Linux
Managing disk space efficiently in Linux requires checking file sizes, directory sizes, and disk partitions regularly. Linux provides simple yet powerful commands to accomplish these tasks.
Check Disk Usage of Files and Directories
To view the total disk space used by specific files or directories, use the du
command:
du -sh dir1 dir2 file1 file2
-
du
: disk usage -
-s
: summarize -
-h
: human-readable format (KB, MB, GB)
Count Lines, Words, and Bytes in Files
To quickly determine how many lines, words, and bytes are in a file, use the wc
command:
wc file
-
Provides number of lines, words, and bytes respectively.
View Current Partition Space
To see the total size, used space, and available space for the current partition, use:
df -h
-
df
: disk filesystem usage -
-h
: human-readable output -
.
: current partition
Check Space on All Partitions
To display disk space information for every partition on your system, use:
df -h
This gives you an overview of disk usage across all partitions.
Regularly using these simple commands can help manage your Linux system’s disk space effectively.