2017-07-27 每天2个Linux命令 df命令
报告文件系统磁盘空间的使用情况。获取硬盘被占用了多少空间,目前还剩下多少空间等信息。
(1)用法:
用法: df [选项] [文件]
(2)功能:
功能: 显示指定磁盘文件的可用空间。如果没有文件名被指定,则所有当前被挂载的文件系统的可用空间将被显示。
默认情况下,磁盘空间将以 1KB 为单位进行显示,除非环境变量 POSIXLY_CORRECT 被指定,那样将以512字节为单位进行显示。
(3)选项参数:
1) -a 全部文件系统列表
2) -h 方便阅读方式显示
3) -H 等于“-h”,但是计算式,1K=1000,而不是1K=1024
4) -i 显示inode信息
5) -k 区块为1024字节
6) -l 只显示本地文件系统
7) -m 区块为1048576字节
8) --no-sync 忽略 sync 命令
9) -P 输出格式为POSIX
10) --sync 在取得磁盘信息前,先执行sync命令
11) -T 文件系统类型
选择参数:
12) --block-size=<区块大小> 指定区块大小
13) -t<文件系统类型> 只显示选定文件系统的磁盘信息
14) -x<文件系统类型> 不显示选定文件系统的磁盘信息
(4)实例:
1)[root@localhost /]# df 列出各文件系统的磁盘空间使用情况
复制代码
[root@localhost /]# df
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/sda3 18555904 3582444 14973460 20% /
devtmpfs 997908 0 997908 0% /dev
tmpfs 1006936 148 1006788 1% /dev/shm
tmpfs 1006936 9072 997864 1% /run
tmpfs 1006936 0 1006936 0% /sys/fs/cgroup
/dev/sda1 303788 113264 190524 38% /boot
2)[root@localhost /]# df -i 列出各文件系统inode使用情况
复制代码
[root@localhost /]# df -i
文件系统 Inode 已用(I) 可用(I) 已用(I)% 挂载点
/dev/sda3 18566144 127865 18438279 1% /
devtmpfs 249477 370 249107 1% /dev
tmpfs 251734 8 251726 1% /dev/shm
tmpfs 251734 489 251245 1% /run
tmpfs 251734 13 251721 1% /sys/fs/cgroup
/dev/sda1 307200 330 306870 1% /boot
3)[root@localhost /]# df -ia |more -10 列出所有文件系统的的inode使用情况,用more命令分隔只显示前10条
复制代码
[root@localhost /]# df -ia |more -10
文件系统 Inode 已用(I) 可用(I) 已用(I)% 挂载点
rootfs 18566144 127865 18438279 1% /
proc 0 0 0 - /proc
sysfs 0 0 0 - /sys
devtmpfs 249477 370 249107 1% /dev
securityfs 0 0 0 - /sys/kernel/security
tmpfs 251734 8 251726 1% /dev/shm
devpts 0 0 0 - /dev/pts
tmpfs 251734 489 251245 1% /run
tmpfs 251734 13 251721 1% /sys/fs/cgroup
--More--
4)[root@localhost /]# df -T 显示各文件系统类型
复制代码
[root@localhost /]# df -T
文件系统 类型 1K-块 已用 可用 已用% 挂载点
/dev/sda3 xfs 18555904 3582964 14972940 20% / //这里貌似没显示ext*文件系统
devtmpfs devtmpfs 997908 0 997908 0% /dev
tmpfs tmpfs 1006936 148 1006788 1% /dev/shm
tmpfs tmpfs 1006936 9072 997864 1% /run
tmpfs tmpfs 1006936 0 1006936 0% /sys/fs/cgroup
/dev/sda1 xfs 303788 113264 190524 38% /boot
5)[root@localhost /]# df -h 以便于阅读的方式显示信息
复制代码
[root@localhost /]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 18G 3.5G 15G 20% /
devtmpfs 975M 0 975M 0% /dev
tmpfs 984M 148K 984M 1% /dev/shm
tmpfs 984M 8.9M 975M 1% /run
tmpfs 984M 0 984M 0% /sys/fs/cgroup
/dev/sda1 297M 111M 187M 38% /boot
[root@localhost /]# df -ih
文件系统 Inode 已用(I) 可用(I) 已用(I)% 挂载点
/dev/sda3 18M 125K 18M 1% /
devtmpfs 244K 370 244K 1% /dev
tmpfs 246K 8 246K 1% /dev/shm
tmpfs 246K 489 246K 1% /run
tmpfs 246K 13 246K 1% /sys/fs/cgroup
/dev/sda1 300K 330 300K 1% /boot
6)[root@localhost /]# df -k 以单位显示磁盘的使用情况(默认)
复制代码
[root@localhost /]# df -kh
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 18G 3.5G 15G 20% /
devtmpfs 975M 0 975M 0% /dev
tmpfs 984M 148K 984M 1% /dev/shm
tmpfs 984M 8.9M 975M 1% /run
tmpfs 984M 0 984M 0% /sys/fs/cgroup
/dev/sda1 297M 111M 187M 38% /boot
[root@localhost /]# df -k
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/sda3 18555904 3582484 14973420 20% /
devtmpfs 997908 0 997908 0% /dev
tmpfs 1006936 148 1006788 1% /dev/shm
tmpfs 1006936 9076 997860 1% /run
tmpfs 1006936 0 1006936 0% /sys/fs/cgroup
/dev/sda1 303788 113264 190524 38% /boot
[root@localhost /]# df
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/sda3 18555904 3582484 14973420 20% /
devtmpfs 997908 0 997908 0% /dev
tmpfs 1006936 148 1006788 1% /dev/shm
tmpfs 1006936 9076 997860 1% /run
tmpfs 1006936 0 1006936 0% /sys/fs/cgroup
/dev/sda1 303788 113264 190524 38% /boot
复制代码
7)[root@localhost /]# df -t tmpfs 显示指定类型的文件系统
复制代码
[root@localhost /]# df -k
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/sda3 18555904 3582508 14973396 20% /
devtmpfs 997908 0 997908 0% /dev
tmpfs 1006936 148 1006788 1% /dev/shm
tmpfs 1006936 9076 997860 1% /run
tmpfs 1006936 0 1006936 0% /sys/fs/cgroup
/dev/sda1 303788 113264 190524 38% /boot
[root@localhost /]# df -t tmpfs
文件系统 1K-块 已用 可用 已用% 挂载点
tmpfs 1006936 148 1006788 1% /dev/shm
tmpfs 1006936 9076 997860 1% /run
tmpfs 1006936 0 1006936 0% /sys/fs/cgroup
2017-07-27 每天2个Linux命令 du命令
du命令是对文件和目录磁盘使用的空间的查看。
(1)用法:
用法: du [选项] [文件]
(2)功能:
功能: 报告磁盘空间使用情况
(3)选项参数:
1) -a --all 显示对所有文件的统计,而不只是包含子目录。
2) -b --bytes 输出以字节为单位的大小,替代缺省时1024字节的计数单位。
3) -h --human-readable 以K,M,G为单位,提高信息的可读性。
4) -s --summarize 对每个参数只显示总和
5) --max-depth=n 只输出命令行参数的小于等于第 n 层的目录的总计。 --max-depth=0的作用同于-s选项。
6) -m --megabytes 输出以兆字节的块为计数单位的大小(就是 1,048,576 字节)
7) -X file --exclude-from=file
除了从指定的文件中得到模式之外与 --exclude 一样。 模式以行的形式列出。如果指定的文件是'-',那么从标准输 入中读出模式。
8) -k --kilobytes 以KB(1024bytes)为单位输出
(4)实例:
默认是1024个字节为单位
1)[root@localhost sunjimeng]# du Documents 显示目录或文件的空间使用情况
复制代码
[root@localhost sunjimeng]# du Documents //只显示目录
0 Documents/findDir/Dir/CDir
12 Documents/findDir/Dir
12 Documents/findDir
8 Documents/Pdir
8 Documents/NoPdir
28 Documents
显示文件的空间使用情况
[root@localhost sunjimeng]# du Documents/findDir/Dir/head_text
4 Documents/findDir/Dir/head_text
2)[root@localhost sunjimeng]# du -a Documents 详细查看当前目录,子目录下的,所有文件和目录
复制代码
[root@localhost sunjimeng]# du -a Documents
4 Documents/findDir/Dir/head_text
4 Documents/findDir/Dir/less2
0 Documents/findDir/Dir/CDir
4 Documents/findDir/Dir/less1.gz
12 Documents/findDir/Dir
12 Documents/findDir
0 Documents/Pdir/find
4 Documents/Pdir/t3.txt
4 Documents/Pdir/vf
0 Documents/Pdir/uText
8 Documents/Pdir
0 Documents/NoPdir/find
4 Documents/NoPdir/t3.txt
4 Documents/NoPdir/vf
0 Documents/NoPdir/uText
8 Documents/NoPdir
28 Documents
复制代码
3)[root@localhost Document]# du 默认显示当前目录的文件夹的空间使用情况
复制代码
[root@localhost Document]# du
0 ./newDir
12 .
[root@localhost Document]# ll
总用量 12
-rw-r--r--. 1 root users 85 5月 18 02:58 all.txt
-rw-rw-r--. 1 sunjimeng users 0 5月 19 22:27 B.text3
-rw-rw-r--. 1 sunjimeng users 0 5月 19 22:27 C.text6
-rw-rw-r--. 1 sunjimeng users 0 5月 19 22:28 D.text
drwxr-xr-x. 2 root users 51 5月 18 02:47 newDir
-rw-r--r--. 1 root users 42 5月 18 02:53 t1.txt
-rw-r--r--. 1 root users 43 5月 18 02:54 t2.txt
[root@localhost Document]# cd ../
[root@localhost sunjimeng]# du Document
0 Document/newDir
12 Document
4)[root@localhost sunjimeng]# du -ah Documents 以易于阅读的方式显示
复制代码
[root@localhost sunjimeng]# du -ah Documents
4.0K Documents/findDir/Dir/head_text
4.0K Documents/findDir/Dir/less2
0 Documents/findDir/Dir/CDir
4.0K Documents/findDir/Dir/less1.gz
12K Documents/findDir/Dir
12K Documents/findDir
0 Documents/Pdir/find
4.0K Documents/Pdir/t3.txt
4.0K Documents/Pdir/vf
0 Documents/Pdir/uText
8.0K Documents/Pdir
0 Documents/NoPdir/find
4.0K Documents/NoPdir/t3.txt
4.0K Documents/NoPdir/vf
0 Documents/NoPdir/uText
8.0K Documents/NoPdir
28K Documents
5)[root@localhost sunjimeng]# du -hba Documents 以一个字节为单位显示
复制代码
[root@localhost sunjimeng]# du -hba Documents
664 Documents/findDir/Dir/head_text
57 Documents/findDir/Dir/less2
6 Documents/findDir/Dir/CDir
67 Documents/findDir/Dir/less1.gz
854 Documents/findDir/Dir
870 Documents/findDir
0 Documents/Pdir/find
85 Documents/Pdir/t3.txt
105 Documents/Pdir/vf
0 Documents/Pdir/uText
241 Documents/Pdir
0 Documents/NoPdir/find
85 Documents/NoPdir/t3.txt
105 Documents/NoPdir/vf
0 Documents/NoPdir/uText
241 Documents/NoPdir
1396 Documents
6)[root@localhost sunjimeng]# du -s * 只以总数显示子文件夹的空间使用情况
复制代码
[root@localhost sunjimeng]# du -s *
0 Desktop
12 Document
28 Documents
0 Downloads
0 findTextDir
0 Music
0 Pictures
0 Public
0 Templates
0 Videos
[root@localhost sunjimeng]# du -s //默认显示当前的文件夹sunjimeng
5328
7)[root@localhost sunjimeng]# du -bh * |sort -n 根据目录的大小进行排序,包括目录的子目录
复制代码
[root@localhost sunjimeng]# du -bh * |sort -n
1.4K Documents
6 Desktop
6 Documents/findDir/Dir/CDir
6 Downloads
6 findTextDir
6 Music
6 Pictures
6 Public
6 Templates
6 Videos
51 Document/newDir
241 Documents/NoPdir
241 Documents/Pdir
321 Document
854 Documents/findDir/Dir
870 Documents/findDir
8)[root@localhost /]# du -ahm --max-depth=0 以M为单位显示文件夹的大小,并且可以指定显示的深度
复制代码
[root@localhost /]# du -ahm --max-depth=0 //深度为0表示只显示当前文件夹/的大小
du: 无法访问"./proc/4599/task/4599/fd/4": 没有那个文件或目录 //但必须将整个磁盘全部查询才知道结果
du: 无法访问"./proc/4599/task/4599/fdinfo/4": 没有那个文件或目录
du: 无法访问"./proc/4599/fd/4": 没有那个文件或目录
du: 无法访问"./proc/4599/fdinfo/4": 没有那个文件或目录
du: 无法访问"./run/user/1000/gvfs": 权限不够
3540 .
[root@localhost /]# du -ahm --max-depth=1
96 ./boot
1 ./dev
du: 无法访问"./proc/4670/task/4670/fd/4": 没有那个文件或目录
du: 无法访问"./proc/4670/task/4670/fdinfo/4": 没有那个文件或目录
du: 无法访问"./proc/4670/fd/4": 没有那个文件或目录
du: 无法访问"./proc/4670/fdinfo/4": 没有那个文件或目录
0 ./proc
du: 无法访问"./run/user/1000/gvfs": 权限不够
9 ./run
0 ./sys
28 ./etc
1 ./root
1 ./tmp
100 ./var
3304 ./usr
0 ./bin
0 ./sbin
0 ./lib
0 ./lib64
6 ./home
0 ./media
0 ./mnt
0 ./opt
0 ./srv
0 ./touch_test
0 ./touch_text
3540 . //可知整个ext文件系统的空间使用情况是3540M左右