Check space usage linux

How to find out how much disk space is remaining?

The -h flag provides human readable output (which makes reading of the output — easier).

du — estimate file space usage

A second tool is with du which is a slower approach but will give you a better break down of a per directory. Information on that can be found in How to determine where the biggest files/directories on my system are stored?

There are several good command line tools for reporting disk usage. Use the one that’s most helpful to you:

df

$ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 56G 4.4G 48G 9% / none 1.5G 256K 1.5G 1% /dev none 1.5G 472K 1.5G 1% /dev/shm none 1.5G 400K 1.5G 1% /var/run none 1.5G 0 1.5G 0% /var/lock tmpfs 1.5G 596K 1.5G 1% /var/log tmpfs 1.5G 8.0K 1.5G 1% /var/log/apt /dev/sdb2 840G 579G 253G 70% /home 

df is installed by default.

pydf

$ pydf Filesystem Size Used Avail Use% Mounted on /dev/sda1 55G 4437M 48G 7.9 [##. ] / none 1506M 256k 1505M 0.0 [. ] /dev /dev/sdb2 839G 578G 252G 68.9 [###################. ] /home 

Column headers are colored.

discus

$ discus Mount Total Used Avail Prcnt Graph / 55.02 GB 4.33 GB 50.69 GB 7.9% [*---------] /sys 0 KB 0 KB 0 KB 0.0% [----------] +onnections 0 KB 0 KB 0 KB 0.0% [----------] +rnel/debug 0 KB 0 KB 0 KB 0.0% [----------] +l/security 0 KB 0 KB 0 KB 0.0% [----------] /dev 1.47 GB 256 KB 1.47 GB 0.0% [----------] /dev/shm 1.48 GB 472 KB 1.48 GB 0.0% [----------] /var/run 1.48 GB 400 KB 1.48 GB 0.0% [----------] /var/lock 1.48 GB 0 KB 1.48 GB 0.0% [----------] /var/log 1.48 GB 596 KB 1.48 GB 0.0% [----------] +ar/log/apt 1.48 GB 8 KB 1.48 GB 0.0% [----------] /home 839.00 GB 578.13 GB 260.87 GB 68.9% [*******---] +infmt_misc 0 KB 0 KB 0 KB 0.0% [----------] +e/ak/.gvfs 0 KB 0 KB 0 KB 0.0% [----------] 

Column headers and progress bars are colored.

di

$ di Filesystem Mount Mebis Used Avail %Used fs Type /dev/sda1 / 56340.2 4436.7 49041.6 13% ext4 /dev/sdb2 /home 859138.9 592008.8 258401.8 70% ext4 tmpfs /var/log 1511.2 0.6 1510.6 0% tmpfs tmpfs /var/log/apt 1511.2 0.0 1511.2 0% tmpfs 

GNOME System Monitor

If you prefer graphical gnome-system-monitor :

Читайте также:  Управление кулерами linux mint

screenshot

Disk Usage Analyzer

screenshot

The Disk Usage Analyzer counterpart for CLI would be ncdu .

For example, du -sh /home/mark will show a summarised usage report in human-readable output for /home/mark .

You can use this command to find out how much space files in your home directory (replace ~/ with / for entire filesystem) and sort by largest files

ncdu

You can also use ncdu (available directly from the Ubuntu repos) which use the ncurses library for showing a graphical overview directly in the terminal.

will analyze disk usage on root partition without crossing filesystem boundaries.

df -h is your best bet (run it in the Terminal).

Note that df -h will show you only remaining space on mounted partitions. Suppose there are NTFS and FAT32 partitions too before running it note that mount all the partitions. If Ubuntu is sole OS on your machine then I don’t see any problem with df .

Get one value that expresses disk utilization in percent

This expression takes all volumes total, available und used space in kB and summarizes the values and finally calculates a total percentage of disk utilization.

df --block-size=1K --output=source,size,used,avail | awk 'NR > 1 END ' 

Use this at your own risk.

This might possibly fail for your use case. If you want to manually check disk utilization df -h will be totally fine.

Again, this is by no means perfect. If you use this, make sure you test this individually on each machine if the volumes you are interested in are covered and represented with the correct return values.

Full command for custom monitoring expressions (e.g. zabbix)

I wanted to exclude volumes whose usage is smaller than 5GB (5000000 kB) and also exclude some other volumes I had no interest in. This works nicely with zabbix or any other monitoring tool that uses custom expressions.

You can debug this by removing the awk expression and decide what you want to include or not.

This command parameterizes a threshold value with a Makro in Zabbix and looks like this:

df --block-size=1K --output=source,size,used,avail | awk '!/tmpfs|loop|shm|overlay|udev/ && $3 >= && NR > 1 END ' 

I was then able to set the default threshold () to 0 and increase it to e.g. 5GB for one machine where I had a volume that I didn’t want to track, since it was almost empty.

Источник

How to Check Disk Space in Linux

Managing disk space on a Linux server is an important task. For example, package manager applications notify you how much disk space will be required for an installation. For that information to be meaningful, you should know how much space your system has available.

Читайте также:  Linux org ru lurk

In this tutorial, learn how to use the df command to check disk space in Linux and the du command to display file system disk space usage.

Tutorial on checking available disk space in Linux

  • A Linux-based system
  • A terminal window / command line
  • A user account with sudo or root privileges

Check Linux Disk Space Using df Command

You can check your disk space simply by opening a terminal window and entering the following:

Command to check disk space on Linux.

The df command stands for disk free, and it shows you the amount of space taken up by different drives. By default, df displays values in 1-kilobyte blocks.

Display Usage in Megabytes and Gigabytes

You can display disk usage in a more human-readable format by adding the -h option:

This displays the size in kilobytes (K), megabytes (M), and gigabytes (G).

Command to check disk space in human-readable format of kilobytes, megabytes,and gigabytes

Understanding the Output Format

The df command lists several columns:

Filesystem Size Used Avail Use% Mounted on udev 210M 0 210M 0% /dev tmpfs 49M 1004K 48M 3% /run /dev/sda2 7.9G 4.3G 3.2G 58% /

Your output may have more entries. The columns should be self-explanatory:

  • Filesystem – This is the name of each particular drive. This includes physical hard drives, logical (partitioned) drives, and virtual or temporary drives.
  • Size The size of the filesystem.
  • Used – Amount of space used on each filesystem.
  • Avail – The amount of unused (free) space on the filesystem.
  • Use% – Shows the percent of the disk used.
  • Mounted on – This is the directory where the file system is located. This is also sometimes called a mount point.

The list of filesystems includes your physical hard drive, as well as virtual hard drives:

  • /dev/sda2 – This is your physical hard drive. It may be listed as /sda1, /sda0, or you may even have more than one. /dev stands for device.
  • udev This is a virtual directory for the /dev directory. This is part of the Linux operating system.
  • tmpfs – You may have several of these. These are used by /run and other Linux processes as temporary filesystems for running the operating system. For example, the tmpfs /run/lock is used to create lockfiles. These are the files that prevent multiple users from changing the same file at the same time.

Display a Specific File System

The df command can be used to display a specific file system:

Читайте также:  Linux mint share desktop

You can also use a backslash:

This displays the usage on your primary hard drive. Use the mount point (in the Mounted on column) to specify the drive you want to check.

Command to display the usage of a specific file system.

Note: The df command only targets a full filesystem. Even if you specify an individual directory, df will read the space of the whole drive.

Display File Systems by Type

To list all file systems by type, use the command:

This lists drives with the ext4 type, in human-readable format.

Command to list drives with the ext4 type with size and available space show

Display Size in 1000 Instead of 1024

You can display disk usage in units of 1000 instead of 1024:

This can address a point of confusion in storage technology. Hard drive manufacturers sell hard drives in sizes based on 1000 bytes = 1 kilobyte.

However, operating systems divide that space up so that 1024 bytes = 1 kilobyte. Because of this, a 1000-gigabyte hard drive ends up with roughly 930 gigabytes of usable storage.

Note: Check out our overview of the Linux free command used to check total, used, shared, free, and available memory and swap space.

Check Disk Space in Linux With du Command

The du command displays disk usage. This tool can display disk usage for individual directories in Linux, giving you a finer-grained view of your disk usage. Use it to display the amount of space used by your current directory:

Du command for displaying disk usage in Linux.

Like the df command, you can make du human-readable:

It displays a list of the contents of the current directory, and how much space they’re using. You can simplify the display with the -s option:

This shows how much space the current directory uses.

example of how much space is left in a linux directory

To specify the directory or file, check use the following options:

With the second command, you may have noticed a permission denied error message. This means the current user doesn’t have the privileges to access certain directories. Use the sudo command to elevate your privileges:

Note: If you’re working on CentOS Linux, you may need to use the su command to switch to the root user to access protected directories.

You should now understand how to use df and du commands to check disk space on your Linux system. Remember, to display a complete list of options, use either df —help or du —help .

Check out our article on how to use fsck command to run a filesystem check as preventive maintenance or when there is an issue with your system.

Источник

Оцените статью
Adblock
detector