最近在清理苹果笔记本空间时,发现一个奇怪的现象,不论删除多少文件,空间就是让不出来,度娘、谷歌都用上了,就是没有查到解决办法,于是乎我决定亲自出马,自己动手、丰衣足食。
苹果自带的磁盘管理工具是diskutil,
查看该命令时,发现有个参数应该能清理空间(此处提醒各位看官,对磁盘对一切操作关乎到数据到完整性及安全性,所以一定要慎重、慎重、再慎重)
zyjsupers-MacBook-Air:etc root# diskutil
Disk Utility Tool
Utility to manage local disks and volumes
Most commands require an administrator or root user
WARNING: Most destructive operations are not prompted
Usage: diskutil [quiet] <verb> <options>, where <verb> is as follows:
...........
eraseDisk (Erase an existing disk, removing all volumes)
eraseVolume (Erase an existing volume)
reformat (Erase an existing volume with same name and type)
eraseOptical (Erase optical media (CD/RW, DVD/RW, etc.))
zeroDisk (Erase a disk, writing zeros to the media)
randomDisk (Erase a disk, writing random data to the media)
secureErase (Securely erase a disk or freespace on a volume)
上面这些参数都是磁盘清理都命令,其中secureErase这个参数都解释是安全清理一块磁盘(看仔细哦,是对一块磁盘进行清理,非常危险的参数)或者一个逻辑卷都空闲空间。
执行下这个命令,可以看到参数如下:
zyjsupers-MacBook-Air:etc root# diskutil secureErase
Usage: diskutil secureErase [freespace] level
MountPoint|DiskIdentifier|DeviceNode
"Securely" (but see "man diskutil") erases either a whole disk
or a volume\'s freespace. Level should be one of the following:
0 - Single-pass zeros.
1 - Single-pass random numbers.
2 - US DoD 7-pass secure erase.
3 - Gutmann algorithm 35-pass secure erase.
4 - US DoE 3-pass secure erase.
Ownership of the affected disk is required.
Note: Level 2, 3, or 4 secure erases can take an extremely long time.
如果加上freespace这个参数就是清理空闲空间,反之则是清理整块磁盘,如果是清理空闲空间的话请切记添加freespace这个参数。
5个清理级别,0 level代表用数字0填充磁盘空间,速度较快,其他几个速度较慢。
看下Man手册中的相关介绍:
secureErase [freespace] level device
Erase, using a "secure" (but see the NOTE below) method, either a whole-disk (including all of its partitions
if partitioned), or, only the free space (not in use for files) on a currently-mounted volume. Secure erasing
makes it harder to recover data using "file recovery" software.
Erasing a whole-disk will leave it useless until it is partitioned again. Erasing freespace on a volume will
leave your files intact, indeed, from an end-user perspective, it will appear unchanged, with the exception
that it will have attempted to make it impossible to recover deleted files.
If you need to erase all contents of a partition but not its hosting whole-disk, use the zeroDisk or
randomDisk verbs. Ownership of the affected disk is required.
Level should be one of the following:
o 0 - Single-pass zero-fill erase.
o 1 - Single-pass random-fill erase.
o 2 - US DoD 7-pass secure erase.
o 3 - Gutmann algorithm 35-pass secure erase.
o 4 - US DoE algorithm 3-pass secure erase.
NOTE: This kind of secure erase is no longer considered safe. Modern devices have wear-leveling, block-spar-
ing, and possibly-persistent cache hardware, which cannot be completely erased by these commands. The modern
solution for quickly and securely erasing your data is encryption. Strongly-encrypted data can be instantly
"erased" by destroying (or losing) the key (password), because this renders your data irretrievable in practi-
cal terms. Consider using APFS encryption (FileVault).
仔细阅读下man手册,整理了一条专用清理空间空间的命令如下:
zyjsupers-MacBook-Air:etc root# diskutil secureErase freespace 0 disk2s1
大概花费了20多分钟,清理出70GB的空闲空间,没发现有其他异常。也不知道什么原理。