Linux Commands for Disk Space

29/12/2020
This tutorial shows Linux commands for disk space information gathering. The commands explained here are df and du, additionally the tutorial shows how to list the largest files in your system

Linux Command for Disk Space information

The df command in Linux systems shows information on the space used and available by disk devices. The first part of this tutorial focuses on showing different options to display information on the storage devices usage.

To begin to print space information on the connected devices run df without flags:

As you see the first column shows the device or partition, the second column shows information on the blocks, then the used and available space followed by the percentage and the last column is the mount point.

We can improve the output by adding the -h flag making it readable by humans.
Run the command df with the -h flag:

# df -h

You can print all sizes in MB by replacing the h for m like the next example:

# df -m

The -T flag instructs df to print the filesystem type of each partition under the new column TYPE, to try it run:

# df -T

Note this is a big case T.

To instruct df to print information on all filesystems use the flag -a (all):

# df -a

You can instruct df to print information on a specific type of filesystem by adding the flag -t (low case) followed by the filesystem type:

# df -t ext4

You can get additional information on the df command on its man page or online at https://linux.die.net/man/1/df.

Linux Linux du Command for Disk Space information

Additionally to the command df to check disk space information on Linux there is the command du (Disk Usage). It is also simple to use, to try it run it without flags:

# du

The last line shows the total amount of space used, over 60 GB, to print the result in human friendly output like with df add the flag -h.

# du -h

With the command du you can specify the location you want to get information about. Just specify a mount point,filesystem, directories or files after the flags, in the next example

# du -h /boot

In the following example I use du to print information on the space used by a simple directory:

You can get additional information on the du command on its man page or online at https://linux.die.net/man/1/du.

Show largest files in Linux

The commands df and du mentioned before are great to show the disk usage by each filesystem, device, partition, directory or file.  But if you want the largest files in your Linux to be listed you can run:

# find / -printf ‘%s %pn’| sort -nr | head -10

The command above will print the 10 biggest files in your system, if you want to display a different number of results replace the number 10, you also change the root volume (/) if you want to show the largest files of a different location.

The following example shows a listing of the 5 largest files within the /usr/ directory:

# find /usr -printf ‘%s %pn’| sort -nr | head -5

I hope you found this brief article on Linux Command for Disk Space useful, thank you for reading it.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

VIM Vundle Tutorial

VIM is a programmable console based text editor. It is highly configurable and it has many plugins. But managing these...
28/12/2020

Vì sao cần thuê proxy xoay? Địa chỉ cung cấp proxy xoay uy tín

Nhu cầu sử dụng proxy ngày càng tăng cao bởi những lợi ích tuyệt vời mà nó đem lại. Một trong...
05/10/2023

Top Lightweight Linux Distributions for 2019

Modern Linux distros are designed to attract a large number of users having machines equipped with the latest hardware....
29/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Tìm Hiểu Về Thuê Proxy US – Lợi Ích và Cách Sử Dụng Hiệu Quả
11/12/2024

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024

Thuê mua IPv4 giá rẻ, tốc độ nhanh, uy tín #1
28/05/2024