How to check disk space in Linux

In this tutorial, we will show you how to use the command df to check the disk space in and the command du to monitor disk usage. If you are a Linux user, these two are essential and will help you manage your files more effectively.

Analyze hard drive

The commands df Y du they have a slightly different purpose when analyzing a hard drive. To avoid confusion, we will explain them in separate sections. Let’s start with the command df.

Check disk space on Linux using the df command

dfWhat does it mean disk file system is used to check disk space. It will show the available and used storage of the file systems on your machine.

To run the command, follow these steps:

  1. press Control + Alt + T to open Terminal.
  2. Enter the command df -h.
  3. in the column Available, you will see the available space of your disk partitions. You will find your main partition at /dev/sda either /dev/sdb.

When you run this command, you will see the default columns: Filesystem, Size, Available, Used, Use% Y Mounted On. Generally it should look like this:

  • file system: Gives you the name of the file system.
  • Size: tells you the total size of each file system.
  • Used: Shows how much space each file system is using.
  • Available: Shows how much available space is left on the file system.
  • Use%: shows the percentage of the space that is being used.
  • Mounted On: tells us the mount point of a file system.

Adding a series of options to the command df, you can check the disk space in Linux more accurately. These are the most popular options:

  • df -h: will show you the result in a format human readable.
  • df -m: This command line is used to display file system usage information on MB.
  • df -k: to display system usage in KB.
  • df -T: This option will display the Type file system (a new column will appear).
  • df –ht /home: allows you to view information from a specific file system in a readable format (in this case the file system /home).
  • df –help: will list other useful commands that you can use, with their descriptions.
See also  How to know what version of WordPress you have?

Check disk space in Linux using the du command

Another very useful command is dushort for Disk Usage. It will show you details about disk usage of files and directories on a Linux computer or server. With the du command, you need to specify which folder or file you want to check. The syntax is as follows:

du

Let’s see an actual use of the du command with the Desktop directory:

  • du /home/user/Desktop/: This command line allows users to view the disk usage of files and folders that are in the Desktop directory (subdirectories are included as well).
  • du -h /home/user/Desktop/: the same as dfthe option -h displays information in a format human readable.
  • du -sh /home/user/Desktop/: The option -s gives us the total size of a specified folder (in this case, the Desktop directory).
  • du -m /home/user/Desktop/: the option -m gives us the sizes of folders and files in Megabytes (we can use -k to see the information in kilobytes).
  • du -h –time /home/user/Desktop/: This reports the last modified date of the displayed files and folders.
  • df –help: Displays a list of available options and what they can be used for.

Combine commands to clean disk space

You can get more information by combining the command df Y du with other arguments. By doing this, you will have a better idea of ​​what files you can delete to free up disk space.

Just remember to start with the command df to see which file system needs the most cleaning. After that, you can proceed with these combinations.

See also  Complete guide to remove malware from WordPress

Sort files by size

First, we assemble the files and folders on Desktop into a readable format using the command du. Next, we use pipe to send the result to the command sortalong with the option -rn. The script will sort all files and folders from largest to smallest to check disk space usage on Linux. The combination should be like this:

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

Remember that you should not necessarily delete files just because they are large. If you’re not careful, you could delete essential files that would break your project.

Exclude by file size

Let’s say you want to see all files that are larger than a certain size. The most effective way to do this is by using the command shown below:

du -h /home/user/Desktop | grep ‘^\s*\+G’

The allows us to search for files based on a specified pattern. In this example, the script will return all files larger than 1 GB. If you want to select the data larger than 1 MB, you can replace the G by M.

Exclude file types

The last combination is useful when you need to exclude a particular file format from the search results. For example:

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

The argument -exclude=».txt» makes the command du show all file formats except documents .txt.

conclusion

The commands df Y du are file management tools that check disk space on Linux and show all the files stored on your machine. It allows you to add certain options (such as -h, -m, -k, etc.) to refine the output according to your needs.

See also  How to get a free domain (2 methods)

What’s cool is that users can get a more specific result by combining du Y df with other commands, like sort, grep Y exclude. Together, they will help you better understand how disk space is being used on your server. Be sure to check out our article to learn more.

If you have any questions, feel free to leave us a comment below.

Gustavo is passionate about creating websites. He focuses on the application of SEO strategies at for Spain and Latin America, as well as the creation of high-level content. When he is not applying new WordPress tricks you can find him playing the guitar, traveling or taking an online course.

Loading Facebook Comments ...
Loading Disqus Comments ...