前言
du 、df 、sort 常常一起结合使用
正文
df
- df -h
<!-- -h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G) -->
iPhone:/private/var/MobileAsset/Assets root# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/disk0s1s1 3.8G 3.5G 278M 93% /
devfs 52K 52K 0 100% /dev
/dev/disk0s1s2 26G 2.0G 24G 8% /private/var
/dev/disk4 236M 69M 167M 30% /Developer
这个参数和sort 的-h 参数意义是一样的
- df -m
iPhone:/var/Keychains root# df -m
Filesystem 1M-blocks Used Available Use% Mounted on
/dev/disk0s1s1 3644 3397 211 95% /
devfs 1 1 0 100% /dev
/dev/disk0s1s2 26597 2058 24540 8% /private/var
/dev/disk4 236 69 167 30% /Developer
du
- which are the larger caches.
In the terminal run du -s /Library/Caches/* | sort -n
- du -sh *
iPhone:~/Library/Caches root# du -sh * |sort -hr
87M com.apple.coresymbolicationd
46M com.apple.pipelined
20M locationd
1.2M Backup
cleanSqlite
- cleanKeychainsSqlite — 简单的方法抽取,更多信息请看see also
//新增/var/Keychains/keychain-2.db
static
void cleanKeychainsSqlite() {
sqlite3 *database;
int openResult = sqlite3_open("/var/Keychains/keychain-2.db", &database);
if (openResult == SQLITE_OK)
{
int execResult = sqlite3_exec(database, "DELETE FROM genp WHERE agrp<>'apple'", NULL, NULL, NULL);
if (execResult != SQLITE_OK) NSLog(@"kniosre: Failed to exec DELETE FROM genp WHERE agrp<>'apple', error %d", execResult);
execResult = sqlite3_exec(database, "DELETE FROM cert WHERE agrp<>'lockdown-identities'", NULL, NULL, NULL);
if (execResult != SQLITE_OK) NSLog(@"kniosre: Failed to exec DELETE FROM cert WHERE agrp<>'lockdown-identities', error %d", execResult);
execResult = sqlite3_exec(database, "DELETE FROM keys WHERE agrp<>'lockdown-identities'", NULL, NULL, NULL);
if (execResult != SQLITE_OK) NSLog(@"kniosre: Failed to exec DELETE FROM keys WHERE agrp<>'lockdown-identities'', error %d", execResult);
execResult = sqlite3_exec(database, "DELETE FROM inet", NULL, NULL, NULL);
if (execResult != SQLITE_OK) NSLog(@"kniosre: Failed to exec DELETE FROM inet, error %d", execResult);
execResult = sqlite3_exec(database, "DELETE FROM sqlite_sequence", NULL, NULL, NULL);
if (execResult != SQLITE_OK) NSLog(@"kniosre: Failed to exec DELETE FROM sqlite_sequence, error %d", execResult);
sqlite3_close(database);
}
else{
NSLog(@"knkniosre: Failed to open /var/Keychains/keychain-2.db, error %d", openResult);
return;
}
}
see also
// Delete cookies, 这些在iOS10 基本用不上
[fileManager removeItemAtPath:@"/var/mobile/Library/Cookies/Cookies.binarycookies" error:nil];
[fileManager removeItemAtPath:@"/private/var/root/Library/Cookies/Cookies.binarycookies" error:nil];
[fileManager removeItemAtPath:@"/var/mobile/Library/Safari/History.plist" error:nil];
[fileManager removeItemAtPath:@"/var/mobile/Library/Safari/SuspendState.plist" error:nil];
<!-- iPhone:/var/Keychains root# du -sh * |sort -hr -->
25M keychain-2.db
sqlite3 *database;
int openResult = sqlite3_open("/var/Keychains/keychain-2.db", &database);
if (openResult == SQLITE_OK)
{
int execResult = sqlite3_exec(database, "DELETE FROM genp WHERE agrp<>'apple'", NULL, NULL, NULL);
if (execResult != SQLITE_OK) NSLog(@"kniosre: Failed to exec DELETE FROM genp WHERE agrp<>'apple', error %d", execResult);
execResult = sqlite3_exec(database, "DELETE FROM cert WHERE agrp<>'lockdown-identities'", NULL, NULL, NULL);
if (execResult != SQLITE_OK) NSLog(@"kniosre: Failed to exec DELETE FROM cert WHERE agrp<>'lockdown-identities', error %d", execResult);
execResult = sqlite3_exec(database, "DELETE FROM keys WHERE agrp<>'lockdown-identities'", NULL, NULL, NULL);
if (execResult != SQLITE_OK) NSLog(@"kniosre: Failed to exec DELETE FROM keys WHERE agrp<>'lockdown-identities'', error %d", execResult);
execResult = sqlite3_exec(database, "DELETE FROM inet", NULL, NULL, NULL);
if (execResult != SQLITE_OK) NSLog(@"kniosre: Failed to exec DELETE FROM inet, error %d", execResult);
execResult = sqlite3_exec(database, "DELETE FROM sqlite_sequence", NULL, NULL, NULL);
if (execResult != SQLITE_OK) NSLog(@"kniosre: Failed to exec DELETE FROM sqlite_sequence, error %d", execResult);
sqlite3_close(database);
}
else NSLog(@"kniosre: Failed to open /var/Keychains/keychain-2.db, error %d", openResult);
在操作过程或者文章有问题的话欢迎在 原文 里提问或指正。