How to Check Disk Space in Linux
If you are a Linux user, checking disk space is essential to keep your system running smoothly. When your system runs out of disk space, it can cause various problems such as system crashes, data loss, and slow performance. In this article, we will discuss the various methods to check disk space in Linux using the df and du commands.
Disk space refers to the amount of storage space available on your hard drive. When you install a program or save a file, it takes up disk space. Over time, this can add up, and you may find yourself running low on disk space. Checking disk space can help you identify which files or directories are taking up the most space so that you can free up space and keep your system running smoothly.
In the following sections, we will discuss the different ways to check disk space in Linux using the df and du commands, as well as graphical tools for checking disk space. We will also provide tips and tricks for using these tools effectively.
How to Check Disk Space in Linux using the DF command
If you are a Linux user, checking disk space is essential to keep your system running smoothly. When your system runs out of disk space, it can cause various problems such as system crashes, data loss, and slow performance. In this article, we will discuss the various methods to check disk space in Linux using the df and du commands.
One of the built-in Linux commands that displays the amount of disk space available and used on file systems is the df (disk free) command. It is a simple and quick method to check disk space in Linux. Here, we will discuss the syntax, usage, output, and some useful tips and tricks for using the df command.
Syntax and Usage of the DF Command
The syntax of the df command is as follows:
df [OPTION]... [FILE]...
The most commonly used options for the df command are:
-a
– Display all file systems, including those that are not currently mounted-h
– Display values in human-readable format (e.g. 1K, 234M, 2G)-T
– Display the file system type
Output of the DF Command
When you run the df command without any options, it displays the disk space usage information for all mounted file systems. The output of the df command includes the following information:
- Total size, used space, and available space: The output shows the total size of the file system, the amount of used disk space, and the amount of available disk space.
- Filesystem type and mount point: The output shows the type of file system (ext4, xfs, tmpfs, etc.) and the mount point (the directory where the file system is mounted).
- Inode usage: The output shows the percentage of inode usage on the file system.
Tips and Tricks for Using the DF Command
Here are some tips and tricks for using the df command effectively:
- Displaying disk usage in human-readable format: Use the
-h
option to display the disk usage in a human-readable format. This makes it easier to read and understand the output. - Displaying file systems by type: Use the
-T
option to display the file systems by type. This can be useful when you want to check the disk space usage of a specific file system type. - Using units of 1000 instead of 1024: By default, the df command uses units of 1024. However, you can use the
-H
option to display the disk usage in units of 1000 instead of 1024. - Using the sudo command to access protected directories: If you are trying to check the disk space of a directory that requires root privileges, use the sudo command before the df command to gain access.
Example Commands and Their Output
Here are some example commands and their output for using the df command:
$ df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 8113344 0 8113344 0% /dev
tmpfs 1627852 1620 1626232 1% /run
/dev/sda1 96993296 8256296 81964084 10% /
tmpfs 8139268 76 8139192 1% /dev/shm
tmpfs 5120 4 5116 1% /run/lock
tmpfs 8139268 0 8139268 0% /sys/fs/cgroup
/dev/sda2 451987136 3143472 426972496 1% /home
tmpfs 1627848 72 1627776 1% /run/user/1000
This output displays the disk space usage information for all mounted file systems.
$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 7.8G 0 7.8G 0% /dev
tmpfs 1.6G 1.6M 1.6G 1% /run
/dev/sda1 93G 8.0G 80G 10% /
tmpfs 7.8G 76K 7.8G 1% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda2 431G 3.0G 407G 1% /home
tmpfs 1.6G 72K 1.6G 1% /run/user/1000
This output displays the disk space usage information in a human-readable format.
$ df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
udev devtmpfs 8113344 0 8113344 0% /dev
tmpfs tmpfs 1627852 1620 1626232 1% /run
/dev/sda1 ext4 96993296
<div style='text-align: center'><iframe width="480" height="360" src="https://www.youtube.com/embed/892FV4232NM" frameborder="0" allow="autoplay; encrypted-media; picture-in-picture" allowfullscreen></iframe></div>
## How to Check Disk Space in Linux using the DU Command
Another built-in Linux command that is used to check disk space in Linux is the `du` (disk usage) command. It is used to estimate the file space usage of a directory or file and its subdirectories. The `du` command is helpful when you want to check the disk space usage of individual directories and files within a file system.
### Syntax and Usage of the DU Command
The syntax of the `du` command is as follows:
```console
du [OPTION]... [FILE]...
Some of the commonly used options for the du
command are:
-h
– Display the sizes in a human-readable format (e.g. 1K, 234M, 2G)--max-depth=N
– Limit the display to N levels of recursion-c
– Display a total sum of all the sizes
Output of the DU Command
When you run the du
command without any options, it displays the size of each directory in the current directory and its subdirectories. The output of the du
command includes the following information:
- The size of the directory or file: The output shows the size of the directory or file in bytes.
- The path of the directory or file: The output shows the path of the directory or file.
According to PhoenixNAP, the du
command is helpful when you want to check the disk space usage of individual directories and files within a file system.
Tips and Tricks for Using the DU Command
Here are some tips and tricks for using the du
command effectively:
- Displaying sizes in a human-readable format: Use the
-h
option to display the sizes in a human-readable format. This makes it easier to read and understand the output. - Limiting the display to a specific level of recursion: Use the
--max-depth=N
option to limit the display to N levels of recursion. This can be useful when you want to check the disk space usage of a specific directory or file. - Displaying a total sum of all the sizes: Use the
-c
option to display a total sum of all the sizes. This can be useful when you want to know the total disk space usage of a specific directory or file.
According to Hostinger, combining the du
command with other arguments can help sort files by size, exclude by file size, and exclude file types.
Example Commands and Their Output
Here are some example commands and their output for using the du
command:
$ du
4 ./dir1
8 ./dir2/subdir2
12 ./dir2
20 ./dir3
44 .
This output displays the size of each directory in the current directory and its subdirectories.
$ du -h
4.0K ./dir1
8.0K ./dir2/subdir2
12K ./dir2
20K ./dir3
44K .
This output displays the size of each directory in a human-readable format.
$ du --max-depth=1
4 ./dir1
12 ./dir2
20 ./dir3
36 .
This output displays the size of each directory in the current directory and its subdirectories up to one level of recursion.
$ du -c
4 ./dir1
8 ./dir2/subdir2
12 ./dir2
20 ./dir3
44 .
44 total
This output displays the size of each directory in the current directory and its subdirectories and also shows the total sum of all the sizes.
How to Check Disk Space in Linux using the NCURSES Disk Usage Analyzer
The ncdu
(NCurses Disk Usage) command is a disk usage analyzer that provides an interactive interface for checking disk space in Linux. It displays the disk usage of a directory and its subdirectories in a detailed and organized manner.
Installing NCURSES Disk Usage Analyzer
To install the ncdu
command on your Linux system, you can use the following command:
$ sudo apt-get install ncdu
Usage of NCURSES Disk Usage Analyzer
When you run the ncdu
command, it provides an interactive interface for checking the disk usage of a directory and its subdirectories. The interface displays the following information:
- The size of the directory or file: The output shows the size of the directory or file in bytes, as well as the percentage of the total disk space used.
- The path of the directory or file: The output shows the path of the directory or file.
You can navigate the interface using the arrow keys, and you can delete files and directories directly from the interface.
Example Commands and Their Output
Here are some example commands and their output for using the ncdu
command:
$ ncdu /
This command checks the disk usage of the root directory.
$ ncdu /home/user1
This command checks the disk usage of the /home/user1
directory.
According to OpenSource, the ncdu
command is a helpful tool for visualizing disk usage in a detailed and organized manner.
Tips and Tricks for Using NCURSES Disk Usage Analyzer
Here are some tips and tricks for using the ncdu
command effectively:
- Deleting files and directories directly from the interface: You can delete files and directories directly from the
ncdu
interface by selecting the file or directory and pressing thed
key. - Sorting directories by size: You can sort the directories by size by pressing the
s
key. - Resizing the terminal window: You can resize the terminal window to fit the
ncdu
interface by pressing ther
key.
According to Linux Foundation, the ncdu
command is a helpful tool for finding the directories and files using the most disk space.
Conclusion
In this section, we learned how to use the ncdu
command to check disk space in Linux. The ncdu
command provides an interactive interface for visualizing disk usage in a detailed and organized manner. It is a helpful tool for finding the directories and files using the most disk space.
Conclusion
In this article, we have covered the different methods to check disk space in Linux. We have learned about the df
and du
commands, as well as the ncdu
command, which provides an interactive interface for checking disk space usage.
By using these commands, you can easily monitor disk space usage on your Linux system, and take appropriate actions to free up disk space when necessary.
Remember to use the -h
option with the df
and du
commands to display the sizes in a human-readable format, and the --max-depth=N
and -c
options to limit the display to a specific level of recursion and to display a total sum of all the sizes, respectively. Also, use the ncdu
command to visualize disk usage in a detailed and organized manner.
We hope that this article has been helpful to you in understanding how to check disk space in Linux. Make sure to check out our other great content for more information on Linux and other related topics.
Happy disk space checking!
FAQ
Who can use the df
and du
commands?
Anyone using a Linux system can use the df
and du
commands to check disk space.
What are the df
and du
commands used for?
The df
and du
commands are used to check disk space usage on a Linux system.
How can I use the df
command to check free disk space?
You can use the df
command with the -h
option to display free disk space in a human-readable format.
How can I use the du
command to display disk usage?
You can use the du
command with the -h
option to display disk usage in a human-readable format.
What is the ncdu
command used for?
The ncdu
command is a disk usage analyzer that provides an interactive interface for checking disk space in Linux.
How can I install the ncdu
command on my Linux system?
You can install the ncdu
command on your Linux system using the command sudo apt-get install ncdu
.