4

Hello everyone, this is Liang Xu.

During work, we often encounter the situation that the disk is full, especially after a server has been running for N years, it will be full of various junk files, such as: intermediate files generated by compilation, packaged image files, log files, etc. Wait.

Don't ask me how I know, my last company server is like this, I need to delete some useless files every day to make some space for work.

How to check the free space of the Linux system disk? Here are five commands that I use frequently in my work.

df command

df command is an abbreviation of the English word disk-free , used to view the available and used disk space in the Linux system. This command generally has the following commonly used options:

  • df -h : Display the disk space in a human-readable format (otherwise the default display unit is bytes, which is not intuitive)
  • df -a : Contains all file systems

  • df -T : Display disk usage and file system type of each block (for example, xfs, ext2, ext3, btrfs, etc.)
  • df -i : Display used and free inodes

If you don't like typing code and prefer to use a graphical interface, then in the GNOME desktop you can use a Disks (gnome-disk-utility) to get this information.

After Disks starts, you can view all the disks detected by the computer, and then click the partition to view detailed information about it, including used space and remaining space.

du command

du command is an abbreviation of the English word disk useage , which displays the disk usage of files, folders, etc. in the default kilobyte size. The commonly used options are as follows:

  • du -h : Display the disk usage of all directories and subdirectories in a human-readable format
  • du -a : Display the disk usage of all files
  • du -s : Only the total is displayed, only the last total value is listed

Similarly, in the GNOME desktop, there is also a Disk Usage , which can intuitively view the disk usage. In the KDE desktop, the corresponding software is Filelight software.

In these two software, the disk usage is mapped to a series of concentric circles, the middle is the basic folder (usually your /home directory, but you can set it yourself), and each outer ring represents a deeper directory level . Hover the mouse on any position, you can get the detailed information of the space occupied by this part of the disk.

ls -al command

ls command is familiar to everyone. Use the ls -al command to list all the contents and size of a specific directory.

stat command

stat command can directly follow the file or directory to display the size and other statistical information of the file/directory or file system.

Linux fdisk -l command

fdisk -l can display disk size and disk partition information.

The above commands are several commands that I use to check the available disk space, and they are all built-in commands of the Linux system, and no additional installation is required. There are also some third-party tools with similar functions, such as Disks , Ncdu and other tools, which can visually display disk space utilization.

Which command do you like best to use? Let's discuss it together in the comment area~


Finally, recently, many friends asked me for Linux learning roadmap , so based on my experience, I spent a month staying up late in my spare time and compiled an e-book. Whether you are in an interview or self-improvement, I believe it will be helpful to you!

Give it to everyone for free, just ask you to give me a thumbs up!

e-book | Linux development learning roadmap

I also hope that some friends can join me to make this e-book more perfect!

Gain? I hope that the old guys will have a three-strike combo, so that more people can read this article

Recommended reading:

Welcome to follow my blog: Liang Xu Linux Tutorial Network , full of dry goods!


良许
1k 声望1.8k 粉丝