Four commands for monitoring disk space in Linux

Source: Internet
Author: User

Whether running a simple Linux desktop or a large Linux server, you need to know the space available for use by the application and track the disk usage of the system. The following describes four core command lines to manage the media environment on Linux.

I. mount command

The mount command is used to mount the media. By default, the mount command displays the list of media devices currently mounted by the system, as shown in:

Only some rows are listed, but it is clear that the mount command provides four pieces of information:

To manually mount a media device to a virtual directory, log on as the root user. The basic command for manually attaching a media device is mount-t type device deirectory.

The type parameter defines the file system type for formatting the disk. The next two parameters define the location of the media device file, and the location of the mount point in the virtual directory. For example, you need to manually mount the USB flash drive on the device/dev/sdb1 to the/media/disk location,

Run the following command: mount-t vfat/dev/sdb1/media/disk. After a media device is mounted to a virtual directory, the root user will have full access permissions to the device, however, access from other users is restricted. However, you can use the directory permission

To control users who can access the device. If you need to use special features in the mount command, the available parameters are shown in the following table:

Nowadays, CD is widely distributed as. iso files on the Internet.. iso files are the complete images of CD in a single file. Most CD burning software packages can create new CD files based on. iso files. One feature of the mount command is that the. iso file can be directly mounted.

To the Linux virtual directory, instead of burning it to the CD. This can be achieved by using the-o parameter in the loop option:

The mount command mounts the. isoCD image file, just as it is a real CD. And allows us to operate on its file system.

Ii. umount command

To remove a removable media device, do not simply remove it from the system. Instead, you should always uninstall it first. The command for detaching a device is umount. The format is simple: umount [directory | device]

The umount command allows you to define a media device by the device location or mount directory name. If the device contains any open files, the system will not allow you to uninstall them, for example:

In the above example, although I have not used a file in the mounted. iso image file, I am still in a directory in the file structure. Therefore, the umount command Cannot uninstall the image file.

Iii. df command

Sometimes you need to know how much disk space a device has. The df command allows us to conveniently view the usage of all mounted disks. As shown in:

The df command displays each mounted file system that contains data. The command displays the following content:

  • Device location
  • Number of data blocks that can be saved (1024 bytes per block );
  • Number of data blocks used (1024 bytes each );
  • Number of available data blocks (1024 bytes each );
  • Percentage of space in use;
  • The mount point of the device.

The df command also provides some different command line parameters, but most of them are rarely used. One of the more common parameters is-h, which is used to display disk space in readable form.

4. Run the du command

With the df command, you can easily check whether the disk space is insufficient. The next question is what to do when the disk space is insufficient. The command that helps us solve this problem is the du command.

The du command displays the disk usage of a specific directory (the default is the current directory ). This is a quick way to determine whether the system has a large disk footprint.

By default, the du command displays all files, directories, and subdirectories in the current directory, and shows how much space each file or directory occupies. For the standard directory, this is a long list. The following shows some of the list displayed by the du command:

The number on the right of each row indicates the number of data blocks occupied by each file or directory. The du command provides command line parameters to improve the readability of the list.

  • -C: generate a total of all listed files.
  • -H: output the size in readable form;
  • -S: Summarize the respective variables;

In itself, the du command is not very useful. Although it can display comprehensive information, it is too comprehensive. When you want to view a file or directory, it needs to be viewed one page at a time, which requires its combination with other file processing commands. It will be mentioned later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.