Linux·28 questions

How to find a large file or free up disk space in Linux?

Answer

A lack of free disk space is a common problem that every Linux user encounters sooner or later. For quick diagnostics of the filesystem state and searching for hidden data accumulations, a combination of built-in command-line utilities is used.

The first step is usually checking the total volume and available space using the df utility with the -h flag for a human-readable format. It shows all mounted partitions and their percentage of filling, which helps immediately determine which specific disk or partition requires attention.

Then, to search for specific heavy directories, the du utility is used. The command with the -s and -h flags for a specified path will output the total size of each folder, allowing you to pinpoint the source of data bloat, for example, in the home directory or the system var directory.

For detailed interactive analysis of disk space, it is strongly recommended to install and use the third-party ncdu utility. It scans the filesystem and displays the results in a pseudo-graphic terminal interface where you can easily navigate through folders and delete unnecessary files right on the fly.

Special attention should be paid to system logs, package manager caches, and old operating system kernels. Regular cleaning of outdated packages and temporary files allows you to free up gigabytes of disk space without the risk of damaging working configurations.

Was this answer helpful?

More questions in this topic

Related questions from other topics