check disks and free space in TB in linux cmd
- User
check disks and free space in TB in linux cmd
- Assistant
To check the disks and free space in TB (terabytes) in a Linux system, you can use the
dfcommand, which displays file system disk space usage. By combining it withawk, you can convert the size from blocks to terabytes for easier readability. Here is a useful command for this purpose:df -BG --total | awk 'NR==1 || /total/ {print $0} {if (NR>1 && $1!="total") sub(/G/,"",$4) } {if (NR>1 && $1!="total") printf "%-20s %-20s %-20s %-20s %-20s\n", $1, $2, $3, $4/1024, $5}'Here's what each part of the command does:
df -BG --total: Run thedfcommand, outputting sizes in gigabytes (-BG) and include a total line (--total).awkscript: Processes thedfoutput to convert values from gigabytes to terabytes (/1024).
The final output gives a clear view of the disk usage in gigabytes and free space in terabytes.
For a simpler and more straightforward command without conversions, the following command will provide the disk usage summary in a human-readable format:
df -hYou can then manually convert the size to terabytes if needed (
1 TB = 1024 GB).However,
df -his generally sufficient for most use cases as it displays the disk usage in the most appropriate units (K,M,G, orT).If you need to consistently show all values in terabytes, you may need to script this further or manually customize the output.