本文的经典应用场景:
1.查找占用磁盘存储空间最大的目录/文件
2.关于【磁盘分区】的相关概念和实操,详见另一博文:[Linux]磁盘分区 - 博客园/千千寰宇
1 fdisk
fdisk := "Partition table manipulator(操纵器) for Linux" := Linux的磁盘分区工具
-l 【查看磁盘所有分区情况】;列出指定设备的分区表信息并退出。 如果没有给出设备,那么使用那些在 /proc/partitions (如果存在)提到的.
-b
-c switch off DOS-compatible mode
-h print help
-u
-v print version;打印 fdisk 的版本信息并退出
-C
-H
-S
- 选择分区磁盘:进入磁盘,分区操作(创建、删除)准备
fdisk /dev/sda
- 在当前磁盘上建立扩展分区
fdisk /ext
- 查看磁盘所有分区情况
[root@test ~]# fdisk -l
Disk /dev/vda: 34.4 GB, 34359738368 bytes, 67108864 sectors 【硬盘vda的总存储空间: 34.4GB】
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos 【硬盘标签类型: dos:= 硬盘采用MBR分区表; gpt := 硬盘采用GPT分区表】
Disk identifier: 0x0009e5d4
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 67108830 33553391+ 83 Linux
/////////////////////////////////////////////////////////////////
[root@test1 ~]# fdisk -l
Disk /dev/loop0: 3916 MB, 3916431360 bytes
64 heads, 32 sectors/track, 3735 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x47840dcd
Device Boot Start End Blocks Id System
/dev/loop0p1 * 1 3735 3824640 17 Hidden HPFS/NTFS
Disk /dev/sda: 536.9 GB, 536870912000 bytes 【注: 硬盘sda总空间: 536.9GB】
255 heads, 63 sectors/track, 65270 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a3902
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 65271 523774976 8e Linux LVM
Disk /dev/mapper/VolGroup-LogVol01: 519.2 GB, 519162560512 bytes
255 heads, 63 sectors/track, 63117 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/VolGroup-LogVol00: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
1 du
du := disk usage
- 查看 目标目录下 占用空间的大小
step1 切换到目标路径
cd <目标目录路径>
step2 执行du
命令
[root@govern /]# du -sh *
5.9M bin
25M boot
260M data
8.0K dedia
160K dev
30M etc
435G home
176M lib
38M lib64
16K lost+found
3.7G media
4.0K mnt
4.2G opt
du: 无法访问"proc/209022/task/209022/fd/4": 没有那个文件或目录
du: 无法访问"proc/209022/task/209022/fdinfo/4": 没有那个文件或目录
du: 无法访问"proc/209022/fd/4": 没有那个文件或目录
du: 无法访问"proc/209022/fdinfo/4": 没有那个文件或目录
du: 无法访问"proc/967628/task/969740/fd/69": 没有那个文件或目录
0 proc
2.8G root
16M sbin
137M sefon
4.0K selinux
4.0K srv
0 sys
1.2M tmp
1.7G usr
7.0G var
du: 无法访问"/proc/209022/task/209022/fd/4": 没有那个文件或目录
du: 无法访问"/proc/209022/task/209022/fdinfo/4": 没有那个文件或目录
du: 无法访问"/proc/209022/fd/4": 没有那个文件或目录
du: 无法访问"/proc/209022/fdinfo/4": 没有那个文件或目录
451G /
2 ls
- 查找占用存储空间超过阈值的文件(及其路径)
[root@xxx ~]# find /home/sdc -type f -size +800M
/home/myTomcat/logs/catalina.out
补充: 此命令(切换到目标路径下) / du -sh *
亦可
- 查看指定文件的大小
[root@xxx ~]#ls -l --block-size='G' /home/myTomcat/logs/catalina.out
-rw-r----- 1 sdc sdc 431G 10月 17 12:03 /home/myTomcat/logs/catalina.out
[root@xxx ~]#ls -l --block-size='M' /home/myTomcat/logs/catalina.out
-rw-r----- 1 sdc sdc 440590M 10月 17 12:03 /home/myTomcat/logs/catalina.out
[root@xxx ~]#ls -l --block-size='K' /home/myTomcat/logs/catalina.out
-rw-r----- 1 sdc sdc 451163616K 10月 17 12:03 /home/myTomcat/logs/catalina.out
[root@xxx ~]# ls -lh
total 565M
-rwxr-xr-x 1 billing_dx BILLING 1.1M Mar 10 18:56 AcctMgrService
-rw-r--r-- 1 billing_dx BILLING 364 Mar 10 18:59 AcctMgrService.conf
-rw------- 1 billing_dx BILLING 11G Mar 13 18:37 core.22836
-rw-r--r-- 1 billing_dx BILLING 410 Mar 13 17:38 dll_info.conf
-rwxr-xr-x 1 billing_dx BILLING 39 Mar 10 18:57 go
补充: 此命令(切换到目标路径下) / du -sh *
亦可