率Linux查看磁盘使用率:一步到位(linux查询磁盘占用)
Modern Linux systems have a wealth of tools available to help users understand their disk usage and query the status of their filesystems. One of the simplest and most commonly used commands is the `df` command, which displays the total size, used and available space and the usage percentage of all mounted filesystems.
In its simplest form the `df` command can be run without any arguments and it will display the disk usage information for all filesystems currently mounted. An example is shown below which is run on a standard Ubuntu Linux distribution.
“`console
$ df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 4915212 0 4915212 0% /dev
tmpfs 1007664 90508 917156 9% /run
/dev/sda1 70372788 37401620 27054108 54% /
On the output, the `Filesystem` field shows the name of the mounted filesystem, e.g. `/dev/sda1`, the `1K-blocks` field shows the total size of the filesystem, `Used` field shows the used space, `Available` field shows the available space and the `Use%` field shows the used percentage. It's worth pointing out that the `Use%` is calculated differently than `Used` divided by `Size` in that it is based on the amount of data that can be stored in the available space.
Using the `-h` option with the `df` command makes the output more human readable by displaying values in a more standard byte size format. This can be very handy when dealing with large filesystems.
```console$ df -h
Filesystem Size Used Avail Use% Mounted onudev 5G 0 5G 0% /dev
tmpfs 1.0G 90M 917M 9% /run/dev/sda1 68G 37G 27G 54% /
Finally the `-a` argument will display all mounted filesystems, including pseudo filesystems such as `/dev`, `/sys`, `/proc` and `/run`.
“`console
$ df -ah
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 68G 37G 27G 54% /
udev 5G 0 5G 0% /dev
tmpfs 1.0G 90M 917M 9% /run
/dev/shm 902M 76K 902M 1% /dev/shm
/run/lock 902M 0 902M 0% /run/lock
/sys/fs/cgroup 902M 12K 902M 1% /sys/fs/cgroup
/run/user/1000 902M 48K 902M 1% /run/user/1000
The `df` command is just one of the many useful tools available to query the state and usage of filesystems on a modern Linux system. As always, it's good practice to periodically review your disk usage to keep it within acceptable limits and to identify any potential problems before they become serious.