Linux Check Disk Space

这里补充一下,常用的关于disk排查的命令就是df, du, dd, lsof, lsblk, blkid, mount, fdisk, mkfs, sync, lvm. More about Linux Storage, see my blog <<Linux Storage System>>.

I get error messages when run docker load command, this is caused by disk space run out. How do I know the disk utilization?

Shows the amount of disk space used and available on Linux file systems.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# disk space report tool, check mount point and fs
# -h: readable
# -T: file system type
$ df [-hT]

Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 241G 219G 23G 91% /
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 8.6M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/vda1 1014M 208M 807M 21% /boot
tmpfs 783M 0 783M 0% /run/user/0

# check mounted filesystem of directory
df -h <directory>
# inode usage of directory
df -i <directory>

Shows total size of the directory and it’s subdirectories

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# du: estimate file space usage

# 统计当前目录下文件大小,并按照大小排序
# -s: display only a total
# -m: --block-size=1M
# *: shell globs
du -sm * | sort -nr
# -BG: blocksize as G
du -s -BG * | sort -nr

# include hidden files
du -sch .[!.]* * | sort -h

# current directory total size
du -sm .

lsof 在这方面主要就是检查哪些文件正在被什么user, process使用:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# see what is interacting with this file
# -l: show user id instead of user name
lsof -l /path/to/file/or/directory

# see files have been opened from a directory
# +D: directory option
lsof +D /var/log

# files opened by process name, wild match by beginning characters
lsof -c ssh
lsof -c init

# files opened by process id
# ^: exclude
lsof -p 5644,^3122

# files opened by user
lsof -u root,1011
lsof -u 1000

# ^: excluding root
lsof +D /home -u ^root

# -a: and operation
# default is or operation
lsof -u mary -c ssh -a

# find deleted file hold by which process
lsof -nP +L1 | grep '(deleted)'

当然在network上lsof也很强大: An lsof primer How to use lsof command

0%