iOS 开发者清理mac内存脚本

这个Shell脚本用于删除Xcode的DerivedData、XCTestDevices、CoreSimulator/Caches以及CocoaPods的缓存,以释放Mac的内存。用户可以执行shclean_my_mac.shall来清理所有缓存,或者shclean_my_mac.shsimple来只清理Xcode相关目录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


function deldir () {
    if [ -d  $1 ]; then
        # echo $1
        rm -rf $1
    fi
}

function getdir(){
    
    echo 'example pods deleteing...'
    for element in `ls $1`
    do  
        dir_or_file=$1"/"$element"/Example/Pods"
        if [ -d $dir_or_file ]; then 
            # echo $dir_or_file
            rm -rf $dir_or_file
        fi
    done
}

function xcodedir () {
    echo 'xcode deleteing...'
    output=$(id -un)

    deviceData="/Users/${output}/Library/Developer/Xcode/DerivedData"
    deldir $deviceData

    xctestdevices="/Users/${output}/Library/Developer/XCTestDevices"
    deldir $xctestdevices
    
    coresimulator="/Users/${output}/Library/Developer/CoreSimulator/Caches"
    deldir $coresimulator
}

function cocoapodsdir () {
    
    echo 'cocoapods deleteing...'
    output=$(id -un)

    cocoapods="/Users/${output}/Library/Caches/CocoaPods/Pods"
    deldir $cocoapods

    cocoapodsstatic="/Users/${output}/Library/Caches/CocoaPods_Static/Pods"
    deldir $cocoapodsstatic
}


simple="simple"
all="all"

xcodedir

if [ $2 ]; then
    getdir $2
fi

if [ $1 == $all ]; then
    cocoapodsdir
fi

以上shell脚本可删除xcode缓存,cocoapods缓存,深度释放mac内存。

使用命令:

sh clean_my_mac.sh all


// 或者

sh clean_my_mac.sh simple

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值