The introduction of
This scenario provides an ECS instance (cloud server) running Aliyun Linux 2. Through this tutorial, you can learn common disk management commands in Linux.
After experiencing this scenario, you can learn the following knowledge: Basic Linux operations.
Ali Cloud ECS experience address can be opened
Disk Management Commands
1. The df command.
Description of the df command: This command checks the disk space usage of the file system. You can use this command to obtain information such as how much space is occupied and how much space is left.
Df command syntax:
Df [parameter] [directory or filename]Copy the code
-a
List all file systems, including system-specific file systems such as /proc.
-k
The capacity of each file system is displayed in KBytes.
-m
In MBytes, the capacity of each file system is returned.
-h
The capacity of each file system is displayed in units of GBytes, MBytes, and KBytes.
-H
The capacity of each file system is displayed in the carry mode of M=1000K instead of M=1024K.
-T
Displays the file system type.
-i
The inode information is displayed.
The df command is used as an example:
Example 1: Display disk usage.
Run the following command to display the disk usage.
df
Copy the code
The result is as follows.Example 2: Show disk usage in inode mode.
Run the following command to display disk usage in inode mode.
df -i
Copy the code
The result is as follows.Example 3: Display all special file formats, names, and disk usage in the system.
Run the following command to display the formats, names, and disk usage of all special files in the system:
df -aT
Copy the code
The result is as follows.Example 4: Display file system capacity in GBytes, MBytes, and KBytes formats.
Run the following command to display the file system capacity in the format of GBytes, MBytes, and KBytes.
df -h
Copy the code
The result is as follows.2. Run the du command.
Description of the du command: View the disk space. The du command differs from the df command in that the du command is used to check the disk space used by files and directories.
Syntax of du command:
Du [parameter] [file or directory name]Copy the code
Parameter Description: -a
Lists all file and directory capacities.
-h
The unit is G, M, and K.
-s
List the total.
-S
Lists total numbers not included in subdirectories.
-k
Returns the capacity in KBytes.
-m
Returns the capacity in MBytes.
An example of the du command is as follows:
Example 1: Lists the capacity of all folders in the current directory.
Run the following command to list the capacity of all folders in the current directory.
du
Copy the code
The result is as follows.
Example 2: Lists the capacity of all folders and files in the current directory.
Run the following command to list the capacity of all folders and files in the current directory.
du -a
Copy the code
The result is as follows.Example 3: List the capacity of all folders and files in the current directory and display the capacity in G, M, and K formats.
Run the following command to list the capacity of all folders and files in the current directory.
du -ah
Copy the code
The result is as follows.
3. Run the fdisk command.
Description of the fdisk command: This command is used to partition disks.
Fdisk syntax:
Fdisk [-l] Indicates the device nameCopy the code
-l
Prints all partition contents for the device name that follows. If there is only fdisk -l, the system will list the partitions of all devices that can be found in the entire system.
An example of the fdisk command is as follows:
Example 1: List partition information for all devices in the system.
Run the following command to list the partition information of all devices in the system.
fdisk -l
Copy the code
The result is as follows.Example 2: List the disk where the root directory resides and view the information about the disk.
A. Run the following command to find the name of the disk where the root directory resides.
df /
Copy the code
The result is as follows.B. Run the following command to partition disk /dev/vda.
fdisk /dev/vda
Copy the code
Note:
When partitioning a disk, the disk name does not contain digits.
The result is as follows.C. Run the following command to obtain help.
m
Copy the code
The result is as follows.
Run the following command to check the disk status.
p
Copy the code
The following information is displayed. You can view the disk status.
D. Run the following command to save no operations and run away.
q
Copy the code
New user experience brought ali cloud T-shirt/recent experience laboratory activities in July (developer.aliyun.com/adc/series/…).