Linux disk management is directly related to the performance of the entire system.

The df, du, and fdisk commands are commonly used to manage disks in Linux.

  • Df: lists the total disk usage of the file system
  • Du: Check the disk space usage
  • Fdisk: used to partition disks

1, df

The df command is used to check the disk space usage of a file system. You can use this command to obtain information such as how much space is occupied by the hard disk and how much space is left.

Grammar:

Df [-ahikhtm] [directory or file name]Copy the code

Options and Parameters:

  • -a: lists all file systems, including system-specific file systems such as /proc.
  • -k: displays each file system in KBytes.
  • -m: Displays each file system in MBytes.
  • ==-h: it is displayed in GBytes, MBytes, and KBytes formats that are easy for people to read. = =
  • -h: carry M=1024K instead of M=1000K;
  • -t: displays the filesystem type, including the filesystem name (for example, ext3) of the partition.
  • -i: displays the number of inodes instead of the disk capacity

Testing:

Lists all file system usage in bytes

/etc = /etc = /etc

2, du

The du command is used to check the space used by files and directories. The du command is used to check the space used by files and directories.

Grammar:

Du [-ahskm] Name of a file or directoryCopy the code

Options and Parameters:

  • -a: lists the capacity of all files and directories. By default, only the number of files under a directory is counted.
  • -h: displays in a capacity format (G/M) that is easy for people to read.
  • -s: Lists the total, not the capacity of each individual directory.
  • -s: excludes totals in subdirectories. It is a little different from -s.
  • -k: The capacity is displayed in KBytes.
  • -m: The capacity is displayed in MBytes.

Testing:

Displays the capacity of all folders (including hidden folders) in the current directory in bytes:

Check the capacity of each directory under the root directory

3, fdisk

Fdisk is a Linux partition table operation tool.

Grammar:

Fdisk [-l] Indicates the device nameCopy the code

Options and Parameters:

  • -l: Output all partitions of the device that follows. If only fdisk -l is used, the system lists all the partitions of devices that can be found in the entire system.

Testing:

List all partition information

Mounting and unmounting disks

To mount disks in Linux, run the mount command. To unmount disks, run the umount command.

Disk mount syntax:

Mount [-t file system] [-l Label name] [-o Extra option] [-n] Mount point of device file nameCopy the code

Umount command syntax:

Umount [-fn] Indicates the device name or mount pointCopy the code

Options and Parameters:

  • -f: Forcibly dismount! It can be used in situations where the network file system (NFS) cannot read it;
  • -n: if /etc/mtab is not upgraded, remove it.