SIGN IN / UP
    opened image

    There are several ways to check disk usage on a Linux operating system without a GUI installed.


    For example, if a web site control panel is installed on the server, you can use its tools. You can find more details about them in the documentation of a specific web panel.


    But it is most convenient to use the console for this by connecting to the server via SSH. Linux systems have several handy applications that can be used for this.


    This article will cover the du and ncdu utilities. The du utility is already installed on your system as it is part of the core Linux file and text utilities (coreutils). The ncdu utility can be installed using your system's package manager.
     

    # For deb-like
    
    apt install ncdu
    
    # For RedHat derivatives (e.g. CentOS)
    
    yum install ncdu


    First, let's check the total amount of used or free disk space. To do this, we will use another built-in df command:

     

    df-h


    Here, the -h switch specifies that the size values should be displayed in a human-readable form (in kilobytes, megabytes, gigabytes).


    First of all, we are interested in the string of the device mounted as the root partition.

     

     

    To check the disk usage of files in the current folder, navigate to the folder and run the command:

     

    du -s -h .


    Here the -s switch means summarize (counting the total amount of space occupied by the files and folders specified in the arguments).

    -h - display size values in a human-readable form (in kilobytes, megabytes, gigabytes).

    . (dot) - on a Linux system, indicates the current directory.


    You can navigate to the desired folder using the cd /path/to/folder command. For example,


     

    cd /var/log


    Keys can be combined together, as shown below. This is a more convenient way to use this command.

     

    du -sh .


    You can also specify the full path to the folder, for example:

     

    du -sh /var/log

     

     

    As arguments, you can specify several paths to the folders you want to check. In the same way, you can check the sizes of all subfolders of the current folder.

     

    du -shc *

     

     

    Here we indicate * (asterix), which means all files and folders in the current directory.

    Using the -c switch, you can calculate the total size occupied by all files specified in the arguments. Adds the total value to the bottom of the list.


    All of the above information is provided in a more convenient form by the ncdu command. Installation of this utility is described at the beginning of the article. Navigate to the desired folder and run the following command:

     

    ncdu


    When the program is launched, the utility calculates the occupied space starting from the folder in which it was launched. This is the start folder. If you need to check the used space for the entire file system, you can go to the root directory (cd /) and run the utility. The counting process can take a long time. In this example, the /usr/share folder is used, as indicated at the top of the application.

     

     

    At startup, you will see the file manager in which the current folder is open. All subfolders and files are here, sorted by actual size.Also pseudo-graphics displays bars showing the relative size of files and folders. The largest file or folder has a completely filled bar.


    With this program, you can check how much space is occupied by the current folder, each subfolder and file in the current folder, you can navigate through subfolders, delete files. You can move through the list items using the cursor keys and the enter key. You can delete files or a folder using the d key. This will generate a warning that can be turned off. Be careful. Deleting files is irreversible on Linux systems.


    To exit the application, use the q button.


    Conclusion

    Utilities for checking disk usage by files and folders in a Linux system without a graphical interface were considered.