Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-2024-05-13· OpenAIAi2 WildChat-4.8M (AI2)

check disks and free space in TB in linux cmd

  1. User

    check disks and free space in TB in linux cmd

  2. Assistant

    To check the disks and free space in TB (terabytes) in a Linux system, you can use the df command, which displays file system disk space usage. By combining it with awk, 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 the df command, outputting sizes in gigabytes (-BG) and include a total line (--total).
    • awk script: Processes the df output 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 -h
    

    You can then manually convert the size to terabytes if needed (1 TB = 1024 GB).

    However, df -h is generally sufficient for most use cases as it displays the disk usage in the most appropriate units (K, M, G, or T).

    If you need to consistently show all values in terabytes, you may need to script this further or manually customize the output.