How to check and manage disk space in Linux
An essential skill required by system administrators is to maintain the 'health' of both online and offline systems. This is especially important on production servers. Downtime or incidents can cause data loss on these servers. A common problem is that updates fail due to a lack of disk space, but there are some simple tests that users can perform when they encounter an error message, to keep critical systems smooth operation.
There are two main commands that can be used:
- df - This command reports the amount of disk space on the system.
- du - This command shows the capacity used by specific files.
Each of the above 2 commands is a different way of checking and can combine both commands at the same time if necessary. Here are some examples to illustrate the use of these commands.
How to control disk space on Linux systems
- Use the df command
- Use du command
- ncdu - Alternative to du
- Good 'cleanup' tools
- Autoremove
- Delete APT cache
- GUI-based options
- Bleachbit
Use the df command
Open Terminal and type df, then press Enter. An output like the following will be displayed:
As can be seen, the results show all drives connected to the system. This result may be somewhat lengthy, so users can collapse the results by specifying the drive that is working. In the examples in this article, the main drive is reported as '/ dev / sda' - The author has also included specific partitions with '/ dev / sda1 ″ and " / dev / sda2'.
Can make df a little easier to read by typing:
df -h
Users can collapse everything more by adding the --output flag . The parameters for this command are:
- source - The source of the device mount point
- size - Total blocks
- used - Total number of blocks used
- avail - Total number of blocks available
- Percent - Percent of used disk space
- target - Mount point for the device
In this example, the author uses only two parameters.
df --output=source,used,avail
Use du command
Users may find that the drive is nearly full, but what causes this situation? This is the time to use the du command to display problem files. In a practical example, a user has detected a remote server with 98% disk space without any warning or real reason. Turns out, there are a lot of log files with java errors, with a total size of about 40GB. There is a lot of wasted disk space, so after using the du command , users can delete unnecessary files.
It should be warned that, if only typing du, the command will return all files and that can take a lot of time. Better define a few parameters. Let's find the 10 largest directories on the system.
du -a / | sort -n -r | head -n 10
This command will scan and create a similar type of result. Ignore warnings about rights at the present time.
For a complete list of usable parameters, see the man page : http://linuxcommand.org/lc3_man_pages/du1.html
ncdu - Alternative to du
If you prefer a more interactive way to view hard drive information, try reviewing ncdu. Ncdu tool provides interface based on ncurses for travelers. This tool displays the same information as the travel command but in a more intuitive way. Ncdu also allows users to navigate between different folders with the arrow keys and use the Enter key to make a selection.
Users can install ncdu in Ubuntu using the command:
sudo apt install ncdu
To use ncdu, enter:
ncdu /directory-to-scan
Replace 'directory-to-scan' to the actual directory you want to scan. For example, to scan the entire hard drive, enter:
ncdu /
Good 'cleanup' tools
In addition to the above commands, there are some basic things users can do to help reduce their disk usage to a minimum.
Autoremove
The most obvious way on Ubuntu-based systems is to check for outdated packages. In Terminal, users can enter:
sudo apt autoremove
When the password has been entered correctly, the system will start deleting the orphaned package (the Orphaned package is a generic term, meaning that the package has no purpose on the running system). It can also remove old kernels that take up space and are mostly unnecessary.
Delete APT cache
When Ubuntu downloads packages, it keeps apt files so they can be easily reinstalled if needed. These files take up disk space and this space can be recovered with:
sudo du -sh /var/cache/apt
Now, it is possible to clean these files with the following command:
sudo apt autoclean
GUI-based options
What if the user feels all of the above Terminal commands are too complicated, or simply doesn't like messing things up with the command line because they can damage the system? Thankfully, Linux has a number of GUI-based tools to use.
Bleachbit
This is a program available for both Windows and Linux systems. Bleachbit works in a similar way on these two platforms. Bleachbit can be downloaded here, but most are available in system repositories. After installation, users can run the tool by selecting the checkboxes.
As the reader has seen, checking the system and the drive capacity will help prevent problems. Users also need to clean the drive regularly.
Hope you are succesful.
You should read it
- How to access user activity on Linux
- How to disable the 'Low Disk Space' warning in Windows 10/8/7
- How to use ncdu to check disk space in Ubuntu
- How much disk space does Windows 10 take?
- Fix log file taking up all Linux drive space
- How to create a Live CD Linux disc
- 11 df commands in Linux (with example)
- Disk Management Tool Windows 10 is about to have a newer, more modern version?
May be interested
- How to Create Disk Images with Disk Utility (Mac OS)if you are running mac os x on your computer, and you want to manage your hard drive, external hard drive, or flash drive, you can os x's native software, disk utility. however, disk utility can not only manage your hard drives and other...
- 4 programs to check Mac storage spacein this article, i will show you three programs and a tip with finder that can know the file size and available disk space on the hard drive.
- How to create a Live CD Linux disca live cd is a bootable cd, dvd or usb drive with an operating system ready to run when the disc is inserted into the computer. this article will show you how to create a linux live cd.
- Try Disk Usage, a new tool to analyze hard drive space on Windows 10disk usage is located in c: windowssystem32diskusage.exe and will display the user guide when entering diskusage / ?. this utility can scan your entire drive or specified folders and report how many each folder is in use.
- How to open Disk Management on Windows 11disk management is basically a utility that allows users to manage all hardware based on the drive recognized by windows. in simple terms, disk management is used to manage the drives installed in the computer such as hard drives (internal and external), optical drives and flash drives.
- How to manage remote Linux server using SSHmanaging the server is still a necessary and sometimes heavy task. fortunately, secure shell (ssh) is available - a network protocol that allows services to run on an unsecured network.
- How much disk space does Windows 10 take?how much disk space does windows 10 ?. in 2016 when it debuted, windows 10 was very compact, lightweight when they weighed only 16gb for 32-bit windows and 20gb for 64-bit versions of windows. but since 2016, windows 10 has gone through dozens of different updates, so they will have the following capacity changes:
- Free up hard drive space automatically on Windows 10 with Disk Cleanupdisk cleanup is one of the 'maintenance' tools built into windows for a long time. this tool allows users to free up more space on the computer by 'cleaning up' the temporary files and the file system is almost no longer usable, but takes up quite a bit of space, unlike files. information to install and update previous windows versions.
- How to clean up junk files to reduce disk space Chow to clean up junk files to reduce disk space c. after a long time using the computer, temporary files will generate junk files and take up hard disk space, sometimes they will make our computer work. no longer as smooth as before. we should correspond
- Disk Quotas configuration in Windows 2003are you looking for means of managing storage space allocated to users? you can use disk quotas. this article gives you an overview of disk quota in windows 2003. we have reviewed the reasons why ch & u