To get information about the total and available space on the Linux file system, you can use the df command.

df

The df command displays information about all mounted filesystems, including total size, space used, percentage usage, and mount point:

[root@myhost /]# df
Filesystem     1K-blocks     Used Available Use% Mounted on
devtmpfs         1866660        0   1866660   0% /dev
tmpfs            1890928        0   1890928   0% /dev/shm
tmpfs            1890928   198152   1692776  11% /run
tmpfs            1890928        0   1890928   0% /sys/fs/cgroup
/dev/sda1       52417516 27336288  25081228  53% /
tmpfs             378188        0    378188   0% /run/user/10000
tmpfs             378188        0    378188   0% /run/user/10001
tmpfs             378188        0    378188   0% /run/user/0
tmpfs             378188        0    378188   0% /run/user/1000

Long lists of space numbers can be difficult to parse. In this case, the -h directive (short for --human-readable ) can be used, which formats the information in a human-readable way:

df -h
[root@myhost /]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        1.8G     0  1.8G   0% /dev
tmpfs           1.9G     0  1.9G   0% /dev/shm
tmpfs           1.9G  194M  1.7G  11% /run
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1        50G   27G   24G  53% /
tmpfs           370M     0  370M   0% /run/user/10000
tmpfs           370M     0  370M   0% /run/user/10001
tmpfs           370M     0  370M   0% /run/user/0
tmpfs           370M     0  370M   0% /run/user/1000
tmpfs           370M     0  370M   0% /run/user/997
tmpfs           370M     0  370M   0% /run/user/10004

To get the total size of a directory, you can use the du command with the s directive:

[root@myhost var]# du -s
19846360        .

The -h directive can also be used to format information in a human-readable way:

[root@myhost var]# du -sh
19G     .

To get the size of each directory and file in a specific directory, you can use the du command with specifying the target * :

du -sh *
[root@myhost var]# du -sh *
0       adm
321M    cache
0       crash
8.0K    db
0       empty
0       games
0       gopher
0       kerberos
16G     lib
0       local
0       lock
215M    log
0       mail
64K     named
0       nis
0       opt
0       parallels
0       preserve
16K     proftpd.delay
178M    qmail
0       run
7.6M    spool
4.0K    tmp
2.5G    www
0       yp

We can extract the largest directories (the top 15) in a given directory using the following set of commands:

du -a . | sort -n -r | head -n 15
[root@myhost var]# du -a . | sort -n -r | head -n 15
19844732        .
16578248        ./lib
15174840        ./lib/psa/dumps
15174840        ./lib/psa
8535596 ./lib/psa/dumps/domains
3838188 ./lib/psa/dumps/domains/mydomain1.com
2748388 ./lib/psa/dumps/domains/mydomain2.com
2530424 ./www
2530380 ./www/vhosts
1362496 ./lib/psa/dumps/domains/mydomain3.tn
1331368 ./www/vhosts/mydomain1.com
1166488 ./lib/mysql
1148928 ./lib/mysql/ibdata1
661220  ./lib/psa/dumps/domains/mydomain1.com/sites
586524  ./lib/psa/dumps/domains/mydomain4.com

Previous Post