西维蜀黍

【Linux】命令 - df

Usage

# Display all filesystems and their disk usage:
$ df

# Display all filesystems and their disk usage in human readable form:
$ df -h

# Display the filesystem and its disk usage containing the given file or directory:
$ df path/to/file_or_directory

# Display statistics on the number of free inodes:
$ df -i

# Display filesystems but exclude the specified types:
$ df -x squashfs -x tmpfs
  ...


【Linux】命令 - stat

Usage

# Show file properties such as size, permissions, creation and access dates among others:
$ stat file

# Same as above but verbose (more similar to linux's stat):
$ stat -x file

# Show only octal file permissions:
$ stat -f %Mp%Lp file

# Show owner and group of the file:
$ stat -f "%Su %Sg" file

# Show the size of the file in bytes:
$ stat -f "%z %N" file
  ...


【Linux】命令 - du

du Command

du command, short for disk usage, is used to estimate file space usage.

The du command can be used to track the files and directories which are consuming excessive amount of space on hard disk drive.

  ...


【Linux】File Systems

Demo

# Create a 10G big file
$ fallocate -l 10G 10g_file.img

$ mkdir sw_test

$ time cp 10g_file.img sw_test/
cp 10g_file.img sw_test/  0.08s user 8.18s system 97% cpu 8.459 total

$ du -h 10g_file.img
11G	10g_file.img

$ du -h sw_test
11G	sw_test

$ stat 10g_file.img
  File: 10g_file.img
  Size: 10737418240	Blocks: 20971528   IO Block: 4096   regular file
Device: fd00h/64768d	Inode: 524359      Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/      sw)   Gid: ( 1000/      sw)
Access: 2021-10-20 00:05:29.925335381 +0800
Modify: 2021-10-20 00:04:17.067027796 +0800
Change: 2021-10-20 00:04:17.067027796 +0800
 Birth: -
$ stat sw_test/10g_file.img
  File: sw_test/10g_file.img
  Size: 10737418240	Blocks: 20971528   IO Block: 4096   regular file
Device: fd00h/64768d	Inode: 2228230     Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/      sw)   Gid: ( 1000/      sw)
Access: 2021-10-20 00:05:29.925335381 +0800
Modify: 2021-10-20 00:05:58.946511217 +0800
Change: 2021-10-20 00:05:58.946511217 +0800
  ...


【Linux】磁盘空间不足 - 扩容

Context

使用 Docker 拉取 MySQL 镜像时发现磁盘空间不够:no space left on device

root@ubuntu:~# docker pull mysql:5.7.29
5.7.29: Pulling from library/mysql
68ced04f60ab: Pull complete 
f9748e016a5c: Pull complete 
da54b038fed1: Pull complete 
6895ec5eb2c0: Pull complete 
111ba0647b87: Pull complete 
c1dce60f2f1a: Pull complete 
702ec598d0af: Pull complete 
63cca87a5d4d: Pull complete 
ec05b7b1c5c7: Extracting [==================================================>]  112.2MB/112.2MB
834b1d9f49b0: Download complete 
8ded6a30c87c: Download complete 
failed to register layer: Error processing tar file(exit status 1): write /usr/sbin/mysqld: no space left on device
  ...