How-To

How to Check and Manage Disk Space in Linux

Managing disk space is one of the major concerns for computer users, irrespective of the platform they use. Especially if you are system admin, your job is to keep an eye on the health of offline and online systems. As low disk space could hinder an update on Linux, which might lead to other critical errors.

Therefore, to know the disk space and amount of space used by specific files, you must be familiar with df and du commands.

In this post, we will discuss how to use df and du commands to check and manage Disk Space on Linux.

DF (Disk filesystem) Command

Launch Terminal. Type df and hit Enter. You will get results as shown in the image below:

It displays a list of disks connected to the system. Locating the disk for which you want to check disk space can be troublesome. Therefore, you can use the command – df /dev/sda1 to check disk space of a specific disk.

If you are unable to understand what is displayed and type in df  -h

If you want to point out things such as a total number of blocks, available blocks, or percentage of used space, use –output flag.

df –output=pcent or df –output=size

Du (Disk Usage) Command

Now that you know how to check the disk space, you must want to know how to manage disk space in Linux. If you have come to know that disk is virtually full, then to resolve the issue, you need to use du command to get problem files. It could be anything, from java error files to cache. So, to delete these files, you can use du.

Note: If you have deleted anything which you didn’t want, you can type du to get all the files. This process can take a lot of time.

Also Read:-
7 Best Open Source Cloning Software for Linux7 best open source disk cloning software for Linux. Here we bring for you a list of Linux disk imaging...

Bonus Tips:

You can use DU command in these ways as well:

If you want to get information related to disk usage by files and folders on the desktop, then type:

 du /home/user/Desktop/

In case, you want to get the above information in a readable format, type in:

 du  -h  /home/user/Desktop/

To know the total size of a folder on the desktop, you can use

du  -sh/home/user/Desktop/

You can also sort files and folders by last modified date, for that type:

du -h –time /home/user/Desktop/

If you want to exclude a certain type of  files and folders during getting the files, type in:

du -h /home/user/Desktop/ –exclude=”*.txt” | sort -rn –

Using txt will exclude these type of files.

You can sort files and folders in descending order, from largest to smallest file by using this command:

du -h /home/user/Desktop/ | sort -rn.

Also Read:-
7 Best Methods To Secure Linux DesktopsWondering whether you need to secure Linux operating system? Linux, being one of the most secure operating system, is still...

So, this is it! These are the basic uses of df and du commands which can help you check and manage disk space on your Linux computer. This will prevent your device from being cluttered.

Liked the article? Please share thoughts in the comments section below.

Leave a comment