
Learn how to check disk space usage in Linux using the most commonly used commands such as ‘df’, ‘du’, ‘df -i’, and ‘du -sh *’. Understand the options and syntax for each command and how to use them to monitor your system’s performance and optimize disk usage
Use the ‘df’ command to check disk space usage in Linux
The ‘-h’ option is used to display the space in human-readable format
df -h
Use the ‘du’ command to check disk usage of a specific directory or file
The ‘-sh’ options are used to display only the total usage of the directory or file in human-readable format
du -sh /path/to/directory
Use the ‘df -i‘ command to check the number of inodes used and available on a file system
df -i
Use the ‘du -sh *‘ command to display the disk usage of all files and directories in a specific directory
du -sh *
Linux Check disk space in GB

To check disk space in GB in Linux, you can use the “df” command with the “-h” option. The “-h” option stands for “human-readable” and it displays the space in a format that is easy to understand, such as GB or MB.
For example, you can use the following command to check the disk space in GB on all mounted file systems:
df -h
This command will show the disk usage in GB or MB. The output will be similar to this:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 20G 12G 7.5G 61% /
/dev/sdb1 100G 50G 49G 50% /mnt
You can also use the command df -BG
or df -H
for displaying the output in GB or df -BM
for displaying the output in MB respectively.
It’s always a good practice to keep an eye on your disk space usage to ensure that your system has enough free space for important tasks. By using the “df” command with the “-h” option, you can easily check the disk space usage in GB on your Linux system.
Linux Check disk space by folder

To check the disk space usage of a specific folder in Linux, you can use the “du” command. The “du” command stands for “disk usage” and it shows the amount of disk space used by a specific directory or file.
For example, you can use the following command to check the disk space usage of a specific folder named “example_folder” in GB:
du -sh /path/to/example_folder
This command will show the total disk space usage of the “example_folder” in human-readable format (i.e. in GB or MB). The output will be similar to this:
3.0G /path/to/example_folder
You can also use the command du
-BG
or du -H
for displaying the output in GB or du -BM
for displaying the output in MB respectively.
Another useful option for the “du” command is the “-a” option, which shows disk usage for all files, including hidden files. For example, you can use the following command to check the disk space usage of a specific folder, including hidden files and folders, in GB:
du -sh -a /path/to/example_folder
It’s important to keep track of the disk space usage of specific folders, especially when working with large files or running low on disk space. By using the “du” command, you can easily check the disk space usage of a specific folder in Linux.
Linux cleans up disk space command line

Use the ‘apt-get’ command to remove unnecessary packages
sudo apt-get autoremove
Use the ‘yum’ command to remove unnecessary packages
sudo yum clean packages
Use the ‘pacman’ command to remove unnecessary packages
sudo pacman -Rns $(pacman -Qtdq)
Use the ‘find’ command to find large files and delete them
find / -type f -size +100M -exec rm -rf {} \;
Use the ‘tmpwatch’ command to delete files that haven’t been accessed in a specified period of time
tmpwatch -am 720 /tmp
Use the ‘logrotate’ command to rotate and compress log files
logrotate -f /etc/logrotate.conf
In the above code snippet, we are using several different command-line tools to clean up disk space in Linux.
The first command, sudo apt-get autoremove, is used to remove packages that were installed as dependencies but are no longer required by any other package in Debian-based systems.
The second command sudo yum clean packages is used to remove packages that were installed but are no longer needed in Red Hat-based systems.
The third command sudo pacman -Rns $(pacman -Qtdq) is used to remove packages that were installed as dependencies but are no longer required by any other package in Arch-based systems.
The fourth command find / -type f -size +100M -exec rm -rf {} \; is used to
Other Related Tutorial:
- How to Enable UTF-8 Support in Linux Terminal
- A Beginner’s Guide To Installing And Configuring Zsh On Ubuntu Linux
- How To Enroll Linux Into Intune
- Ubuntu Linux RTL8821CU Driver Installation
FAQs
What is disk space in Linux and why is it important to check it?
Disk space refers to the amount of storage capacity available on a hard drive or solid-state drive (SSD). It is important to check disk space in Linux to ensure that there is enough space available to store data, install new software, and run applications without any performance issues.
How can I check the disk space in Linux?
There are several ways to check disk space in Linux. One common method is to use the df command in the terminal. Simply open the terminal and type “df” followed by the name of the partition or file system you want to check. For example, to check the disk space of the root partition, type “df /“. The command will display the total, used, and available disk space in a table format.
Can I check the disk space of all partitions at once?
Yes, you can use the “df -h” command to display the disk space of all partitions in human-readable format. The “-h” option makes the output easier to read by displaying the sizes in gigabytes, megabytes, or kilobytes instead of bytes.
How do I check the disk space of a specific directory?
You can use the “du” command to check the disk space used by a specific directory. Open the terminal and type “du” followed by the path of the directory you want to check. For example, to check the disk space used by the /home/user/Documents directory, type “du /home/user/Documents“. The command will display the total size of the directory in bytes.
How do I check the disk space usage of a file?
You can use the “du” command with the “-h” option to display the disk space usage of a file in human-readable format. Open the terminal and type “du -h” followed by the name of the file. For example, to check the disk space usage of a file named “myfile.txt” in the current directory, type “du -h myfile.txt“.
What should I do if I am running out of disk space?
If you are running out of disk space, you can free up space by deleting unwanted files, uninstalling unused software, or moving large files to an external drive. You can also expand the disk space by adding a new hard drive or partitioning an existing one.