Linux disk usage analyzer console

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 :

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.

Читайте также:  Перезагрузка сетевой службы astra linux

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 analyse disk usage in command line linux?

du and df are nice, but I don’t know how to filter the data they provide the way I do with SequoiaView. I would like to know which are the largest folders and the largest files in a glance.

7 Answers 7

You might also want to try the NCurses Disk Usage aka ncdu .

Use it like ncdu -x -q if you’re invoking it remotely (e. g. via ssh ) and ncdu -x otherwise.

ncdu 1.6 ~ Use the arrow keys to navigate, press ? for help --- /home/geek ----------------------------------------------------------------- 27.6MiB /qm test 1 rework 312.0kiB /sidebar 88.0kiB /rackerhacker-MySQLTuner-perl-6add618 8.0kiB /.w3m 4.0kiB /.cache e 4.0kiB /.ssh 160.0kiB ng.tar.gz 76.0kiB plowshare_1~svn1673-1_all.deb 4.0kiB .bashrc 4.0kiB .bash_history 4.0kiB .profile 4.0kiB .htoprc 4.0kiB .bash_logout 0.0 B .lesshst 

This is available under Mac OS X too.

The following flags to the command line might be helpful:

-q Quiet mode, doesn't update the screen 10 times a second while scanning, reduces network bandwidth used -x Don't cross filesystem borders (don't descend into a directory which is a mounted disk) 

Use some combination of the commands and options:

du --max-depth=1 2> /dev/null | sort -n -r | head -n20 

to view only the largest few. If you’d like to use it a lot, then bind it to an alias, e.g. in bash by adding to ~/.bashrc

alias largest='du --max-depth=1 2> /dev/null | sort -n -r | head -n20' 

I submitted @RedGrittyBrick suggestion and an error redirection to /dev/null as an edit subject to approval.

Читайте также:  Configuring host in linux

My modified version of this to display values in human readable format: du -h —max-depth=1 2> /dev/null | sort -h -r

I would like to recommend dutree, which offers a hierachical visualization.

You can select more or less levels of detail, and exclude paths for better control of visualization. You can also compare different paths.

enter image description here

It is implemented in Rust, fast and efficient.

$ dutree -h Usage: dutree [options] [..] Options: -d, --depth [DEPTH] show directories up to depth N (def 1) -a, --aggr [N[KMG]] aggregate smaller than N B/KiB/MiB/GiB (def 1M) -s, --summary equivalent to -da, or -d1 -a1M -u, --usage report real disk usage instead of file size -b, --bytes print sizes in bytes -f, --files-only skip directories for a fast local overview -x, --exclude NAME exclude matching files or directories -H, --no-hidden exclude hidden files -A, --ascii ASCII characters only, no colors -h, --help show help -v, --version print version number 

Источник

How to Analyze Disk Usage in Linux?

Linux disks are similar to the partitions of Windows, which are made on the hard disk to store the data of the operating system as well as to store other files and data. To manage the data on the disk in a Linux distribution, we should know the free and occupied disk space. Considering the importance of the disk usage analysis, this blog demonstrates different methods to analyze disk usage on a Linux:

  • What is Disk Usage in Linux?
  • Method 1: Using the df Command Line Utility
  • Method 2: Using the du Command Line Utility
  • Method 3: Using ncdu Utility
  • Method 4: Using the Graphical Interface Method

What is Disk Usage in Linux?

When the Linux OS is installed, some space on the hard disk is assigned to the Linux OS. In this space, the configuration files of the operating system are stored. Similarly, any new package addition or file addition also occupies space. The hard disk’s space assigned to the Linux is known as a disk, and the space occupied by the Linux is known as Disk Usage in Linux.

Let’s discuss the methods to analyze disk usage in Linux.

Method 1: Using the df Command Line Utility

The df command is used to display the information on the available space as well as the space occupied by different files in Linux. The general syntax of using the df command is:

The “df” command utility can be run with different options and file names. The options supported by the “df” utility are shown below:

General Usage

We can also run the “df” command without options and specifying the file name. For example, we run the “df” command in the terminal:

In the above figure, we can see the space usage by different files under different columns whose explanation is:

Filesystem It displays the file whose information is displayed
1k-blocks It shows the total space of memory in kilobytes units
Used It displays the used memory space
Available It displays the available memory space
Use% It displays the used memory in percentage
Mounted on It displays the disk on which it is mounted
Читайте также:  Linux проверить дисковое пространство

Get the Output in Human Readable Format

To see the above output in human-readable format, we will use the “-h” opinion with the df command:

Get All the Disks Usage in a Human Readable Format

And to get the information of all the disks usage with the “df” command, we will use “-a” option with the “df” command:

This is the easiest way for analyzing the usage of the disk in Linux.

Method 2: Using the du Command Line Utility

The “df” command utility is similar to the “df” command and displays the disk usage of the files in Linux. The difference between “df” and the “du” command is that the “df” command displays the disk usage by the files, whereas the “du” command shows the disk usage by the set of the files (directories). The general usage syntax of the du command is:

The options can be obtained via the following command:

Using a Simple du

The “du” command can also be used without specifying the files and their option; for example, we run the “du” command:

Get the Disk Usage of All Disks in Human Readable Format

Again, similar to the “df” command, to view the output of the du command in human-readable format, we will use the “-h” option and to view the disk usage of all the files, use the “-a” option:

The above output is displaying the disk usage in Linux.

Method 3: Using ncdu Utility

Other than the commands, different packages can be installed on Linux to analyze the disk usage in Linux. The simplest and most used package to analyze disk usage in Linux is “ncdu” which can be installed on Debian-based Linux distributions by using the command:

To install “ncdu” on other distributions:

Fedora-based Linux Distributions

CentOS-based/RHEL-based Linux Distributions

To find out the information on the disk usage with the “ncdu” package, use the command:

The above figure displays the output of the “ncdu” command ad to install the “ncdu”.

Method 4: Using the Graphical Interface Method

The most convenient method to analyze disk usage in Linux is y using the default GUI application of Linux distribution. To open the GUI application, type “disk usage” in the application’s search bar:

The three options displayed in our case, first is the home directory, secondly is a user account, and lastly, the VirtualBox usage:

If we click on the “Home Folder”, then the memory usage of the Home directory is displayed:

Memory used by all the directories of the Home Folder has been demonstrated by different colors. Similarly, if we click on the “Foss‘:

It displays the memory usage of the “Foss” user account” in different colors, as shown in the above figure.

That’s all about this tutorial!

Conclusion

To analyze the disk usage in Linux, run the “df” command, the “du” command in the terminal, and the GUI application. Third-party packages like “ncdu” can also be used for this purpose. In this write-up, the information on the disk usage has been displayed on the screen b running commands ad using the third-party packages as well.

Источник

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