How to check the size of each folder in Linux

This article will introduce two methods to check the size of folders in Linux systems.

Method 1: Use the du command

The du command is a tool used in Linux systems to estimate file and directory capacity. With the du command, you can view the size of a folder and sort it according to the directory hierarchy.

To view the size of a folder, you can use the du command following the following syntax:

du [options] [directory]

Among them, the options can be adjusted as needed. Some commonly used options include:

-h: Display the size of files and directories in human-readable format.

-s: Only displays the total size of the specified directory, not the size of subdirectories.

-c: Display the total size on the last line, including the size of all specified directories.

For example, to view the size of all files and subdirectories in the current directory, you can use the following command:

you h

To view the size of a specific directory, you can specify the path to the directory in the command, for example:

du -h /path/to/directory

Method 2: Use ncdu command

ncdu is a powerful command line tool for interactively viewing the size of files and directories in a Linux system. The ncdu command allows users to browse files and directories in a visual interface and sort them by size.

To use the ncdu command, you first need to install the command line tool. ncdu can be installed in Debian/Ubuntu systems using the following command:

sudo apt install ncdu

Once the installation is complete, you can use the following syntax to run the ncdu command:

ncdu [options] [directory]

Among them, the options can be adjusted as needed. Some commonly used options include:

-r: Display the size of files and directories recursively.

-x: Exclude directories outside the mount point.

-q: Do not display the progress bar.

For example, to view the size of the current directory and its subdirectories, you can use the following command:

ncdu -r /

Guess you like

Origin blog.csdn.net/taoxicun/article/details/133164587