Меню Рубрики

Disk space linux show

Linux Check Disk Space Command To View System Disk Usage

Linux commands to check disk space using:

  1. df command – Shows the amount of disk space used and available on Linux file systems.
  2. du command – Display the amount of disk space used by the specified files and for each subdirectory.
  3. btrfs fi df /device/ – Show disk space usage information for a btrfs based mount point/file system.

Linux check disk space with df command

  1. Open the terminal and type the following command to check disk space.
  2. The basic syntax for df is:
    df [options] [devices]
    Type:
  3. df
  4. df -H

Fig.01: df command in action

See information about specific filesystem

You can give a device or mount point as an argument, and df report data only for the filesystem physically residing on that device. For example, the following command provides information only for the partition /dev/sda:
$ df /dev/sda
$ df -h /dev/sdc1
$ df /data/
Sample outputs:

Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda 2930266584 69405248 2859579472 3% /data

Understanding df command output

The valid fields are as follows:

Display name Valid field name (for —output option) Description
Filesystem source The source of the mount point, usually a device.
1K-blocks size Total number of blocks.
Used used Number of used blocks.
Available avail Number of available blocks.
Use% pcent Percentage of USED divided by SIZE.
Mounted on target The mount point.

You can pass the output format defined by ‘valid field name’ as follows:
$ df —output=field1,field2.
$ df —output=source,used,avail /data/
Sample outputs:

Filesystem Used Avail /dev/md0 5.4G 115G udev 0 11M tmpfs 6.2M 414M tmpfs 4.1k 1.1G tmpfs 4.1k 5.3M tmpfs 0 1.1G /dev/md2 818G 688G tmpfs 0 210M tmpfs 0 210M /dev/mapper/cryptvg-mybackup 77G 526G

You can print all available fields, enter:
$ df —o
Sample outputs:

Filesystem Type Inodes IUsed IFree IUse% 1K-blocks Used Avail Use% File Mounted on udev devtmpfs 379248 333 378915 1% 10240 0 10240 0% — /dev tmpfs tmpfs 381554 498 381056 1% 610488 9704 600784 2% — /run /dev/sdc1 ext3 956592 224532 732060 24% 14932444 7836056 6331204 56% — / tmpfs tmpfs 381554 1 381553 1% 1526216 0 1526216 0% — /dev/shm tmpfs tmpfs 381554 4 381550 1% 5120 0 5120 0% — /run/lock tmpfs tmpfs 381554 14 381540 1% 1526216 0 1526216 0% — /sys/fs/cgroup /dev/sda btrfs 0 0 0 — 2930266584 69405248 2859579472 3% — /data tmpfs tmpfs 381554 4 381550 1% 305244 0 305244 0% — /run/user/0

Express df output in human readable form

Pass the -h option to see output in human readable format. You will device size in gigabytes or terabytes or megabytes:
$ df -h ### Human format
$ df -m ### Show output size in one-megabyte
$ df -k ### Show output size in one-kilobyte blocks (default)

Display output using inode usage instead of block usage

An inode is a data structure on a Linux file system that stores all information about file. To list inode information, enter:
$ df -i
$ df -i -h
Sample outputs:

Filesystem Inodes IUsed IFree IUse% Mounted on udev 371K 333 371K 1% /dev tmpfs 373K 498 373K 1% /run /dev/sdc1 935K 220K 715K 24% / tmpfs 373K 1 373K 1% /dev/shm tmpfs 373K 4 373K 1% /run/lock tmpfs 373K 14 373K 1% /sys/fs/cgroup /dev/sda 0 0 0 — /data tmpfs 373K 4 373K 1% /run/user/0

Find out the type of each file system displayed

Pass the -T option to display the type of each filesystems listed such as ext4, btrfs, ext2, nfs4, fuse, cgroup, cputset, and more:
$ df -T
$ df -T -h
$ df -T -h /data/
Sample outputs:

Limit listing to file systems of given type

The syntax is:
$ df -t ext3 #Only see ext3 file system
$ df -t ext4 #Only see ext4 file system
$ df -t btrfs #Only see btrfs file system

Exclude given file system type

To list all but exclude ext2 filesystem pass the -x TYPE option, enter:
$ df -x ext2

Show all file system

Pass the -a or —all option to the df command to include in its output filesystems that have a size of zero blocks, run:
$ df -a

These file systems omitted by default.

Getting more help about the df command

Pass the —help option see a brief help message:
$ df —help
Or read its man page by typing the following command:
$ man df

Linux check disk space with the du command

The NA command is very useful to track down disk space hogs. It is useful to find out the names of directories and files that consume large amounts of space on a disk. The basic syntax is:
du
du /path/do/dir
du [options] [directories and/or files]
To see the names and space consumption of each of the directories including all subdirectories in the directory tree, enter:
$ du
Sample outputs:

The first column is expressed in kilobytes (file size) and the second column is the filename or directory name.

See du output in human readable format

Pass the -h option to display size in K (kilobytes), M (megabytes), G (gigabytes) instead of the default kilobytes:
$ du -h
Sample outputs:

Finding information about any directory trees or files

To find out /etc/ directory space usage, enter:
# du /etc/
# du -h /etc/
The following will report the sizes of the thee files named hdparm, iptunnel and ifconfig that are located in the /sbin directory:
$ du /sbin/hdparm /sbin/iptunnel /sbin/ifconfig
$ du -h /sbin/hdparm /sbin/iptunnel /sbin/ifconfig
Sample outputs:

How do I summarize disk usage for given directory name?

Pass the -s option to the du command. In this example, ask du command to report only the total disk space occupied by a directory tree and to suppress subdirectories:
# du -s /etc/
# du -sh /etc/
Sample outputs:

Pass the -a (all) option to see all files, not just directories:
# du -a /etc/
# du -a -h /etc/
Sample outputs:

You can also use star ( * ) wildcard, which will match any character. For example, to see the size of each png file in the current directory, enter:
$ du -ch *.png

The -c option tells du to display grand total.

Putting it all together

To list top 10 directories eating disk space in /etc/, enter:
# du -a /etc/ | sort -n -r | head -n 10
Sample outputs:

For more information on the du command, type:
$ man du
$ du —help

Dealing with btrfs file system

For btrfs filesystem use the btrfs fi df command to see space usage information for a mount point. The syntax is:

btrfs filesystem df /path/ btrfs fi df /dev/path btrfs fi df [options] /path/

Examples

# btrfs fi df /data/
# btrfs fi df -h /data/
Sample outputs:

To see raw numbers in bytes, run:
# btrfs fi df -b /data/
OR
# btrfs fi df -k /data/ ### show sizes in KiB ##
# btrfs fi df -m /data/ ### show sizes in MiB ##
# btrfs fi df -g /data/ ### show sizes in GiB ##
# btrfs fi df -t /data/ ### show sizes in TiB ##

Conclusion

Here is quick summary for Linux check disk space commands. Use the du command when you need to estimate file space usage. To report Linux file system disk space usage use the df command. The btrfs df command must be used when using btrfs file system. Fore more info see GNU coreutils page here.

Источник

Linux / Unix – Checking Free Disk Space

Tutorial details
Difficulty Easy (rss)
Root privileges No
Requirements None
Time 1m

(a) df command : Report file system disk space usage.

(b) du command : Estimate file space usage.

df command examples to check free disk space

Type df -h or df -k to list free disk space:
$ df -h
OR
$ df -k
Sample outputs that show disk space utilization:

The df utility displays statistics about the amount of free disk space on the specified file system or on the file system of which file is a part. Values are displayed in 512-byte per block counts. The -H option is called as “Human-readable” output. It use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the number of digits to four or fewer using base 10 for sizes i.e. you see 30G (30 Gigabyte).

How to check free disk space in Linux

To see the file system’s complete disk usage pass the -a option:
df -a
Find out disk usage and filesystem type by passing the -T option:
df -T
Want to get used and free inodes information on Linux? Try:
df -i

du command examples for checking free and used disk space

The du command shows how much space one ore more files or directories is using, enter:
$ du -sh
Sample outputs:

Fig.01: Unix df and du command outputs from my FreeBSD server

Say hello to ncdu command

ncdu (NCurses Disk Usage) is a curses-based version of the well-known ‘du’, and provides a fast way to see what directories are using your disk space. One can install with the following apt command/apt-get command:
sudo apt install ncdu
For RHEL/CentOS, first enable EPEL repo (see CentOS 8 turn on EPEL repo and RHEL 8 enable epel repo) and type the following yum command:
sudo yum install ncdu
Now just type:
ncdu
ncdu [dir] ncdu /etc/

GUI program

Above programs are good if GUI is not installed or you are working with remote system over the ssh based session. Linux and UNIX-like oses comes with KDE and Gnome desktop system. You will find Free Disk Space Applet located under GUI menus. Here is a sample from Fedora Linux version 22 system:

Conclusion

You learned how to keep track of disk utilization, and disk space with various Linux and Unix commands.

Источник

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

  • Instagram direct mac os
  • Inside game mac os
  • Insert button mac os
  • Incorrect number of thread records mac os
  • Imperial glory mac os