mac os 更改微信目录到外接硬盘ok
1.格式化外接硬盘添加卷宗
启动台》其他》磁盘工具》选择磁盘》格式化成 APFS》名称 MacDATA
右键 MacDATA》添加 APFS 卷宗》名称为 comtencentxinWeChat
一般情况创建的应该是设备:/dev/disk5s2,装载点/Volumes/comtencentxinWeChat
2.拷贝数据
校对信息(检查是否为/dev/disk5s2)
diskutil list
sudo diskutil info /dev/disk5s2
#Volume UUID: 9F2ACF6B-9DED-49CD-8E3D-CBFE508401BA
拷贝数据
!!!!以下内容记得替换用户名!!!!
cd /Users/chenchang/Library/Containers/com.tencent.xinWeChat/Data/Library/Application\ Support/com.tencent.xinWeChat
sudo cp -r -v * /Volumes/comtencentxinWeChat
#拷贝所有文件
sudo cp -r -v .* /Volumes/comtencentxinWeChat
#拷贝所有隐藏文件
清除原始文件(确定拷贝完成后操作!!!)
cd /Users/chenchang/Library/Containers/com.tencent.xinWeChat/Data/Library/Application\ Support/com.tencent.xinWeChat
sudo rm -r /Users/chenchang/Library/Containers/com.tencent.xinWeChat/Data/Library/Application\ Support/com.tencent.xinWeChat/*
sudo rm -r /Users/chenchang/Library/Containers/com.tencent.xinWeChat/Data/Library/Application\ Support/com.tencent.xinWeChat/.*
#这条命令确认进入到目录了之后在操作.*是删除隐藏文件
挂载
diskutil unmount /dev/disk5s2
diskutil mount -mountPoint "/Users/chenchang/Library/Containers/com.tencent.xinWeChat/Data/Library/Application Support/com.tencent.xinWeChat" /dev/disk5s2
测试
点开微信进行测试,如果成功则没有修复提示,并且有之前的聊天记录
至此为止更改完毕,但每次重启不能自动挂载。需要手动运行两条挂载命令
3.自动挂载
有人说/etc/fstab可以自动挂载但是我从未成功,而且通过磁盘工具创建的硬盘会自动挂载到/Volumes/comtencentxinWeChat,于是只能曲线救国,原理是创建脚本,登录终端自动运行脚本
创建脚本
cd ~
touch start.sh
chmod a+x start.sh
写入命令内容
echo '#!/bin/bash
diskutil unmount /dev/disk5s2
diskutil mount nobrowse -mountPoint "/Users/chenchang/Library/Containers/com.tencent.xinWeChat/Data/Library/Application Support/com.tencent.xinWeChat" /dev/disk5s2' > start.sh && chmod +x start.sh
#nobrowse为不显示在访达中
检查内容
cat start.sh
##!/bin/bash
#diskutil unmount /dev/disk5s2
#diskutil mount nobrowse -mountPoint "/Users/chenchang/Library/Containers/com.tencent.xinWeChat/Data/Library/Application Support/com.tencent.xinWeChat" /dev/disk5s2
测试脚本
./start.sh
#disk5s2 was already unmounted
#Volume comtencentxinWeChat on /dev/disk5s2 mounted
检查磁盘工具中设备:
/dev/disk5s2,装载点:/Users/chenchang/Library/Containers/com.tencent.xinWeChat/Data/Library/Application Support/com.tencent.xinWeChat
登录自动运行脚本
系统设置》通用》登录项与扩展》登录时打开》+》
start.sh访达用户文件夹里用户名文件夹中找到
start.sh》右键其他》应用程序》使用工具》终端.app》勾选始终以此方式打开》打开。
4.重启测试
重启并打开磁盘工具与微信测试。
5.如果重启/dev/diskxs2总变动则更改脚本
#!/bin/bash
#diskutil unmount /dev/disk5s2
#diskutil mount nobrowse -mountPoint "/Users/chenchang/Library/Containers/com.tencent.xinWeChat/#Data/Library/Application Support/com.tencent.xinWeChat" /dev/disk5s2
# 获取 diskutil list 的最后 7 个字符(如 disk5s2)
# DISK_PARTITION=$(diskutil list | tr -d '\n' | tail -c 7)
DISK_PARTITION=$(diskutil list | grep "comtencentxinWeChat" | awk '{print substr($0, length($0)-6, 7)}')
# 检查是否成功获取分区标识符
if [[ -z "$DISK_PARTITION" ]]; then
echo "错误:无法获取磁盘分区标识符!"
exit 1
fi
echo "检测到的分区:/dev/$DISK_PARTITION"
# 卸载分区
diskutil unmount "/dev/$DISK_PARTITION"
if [[ $? -ne 0 ]]; then
echo "警告:卸载 /dev/$DISK_PARTITION 失败(可能已卸载或不存在)。"
fi
# 重新挂载到微信的目录
MOUNT_POINT="/Users/chenchang/Library/Containers/com.tencent.xinWeChat/Data/Library/Application Support/com.tencent.xinWeChat"
diskutil mount nobrowse -mountPoint "$MOUNT_POINT" "/dev/$DISK_PARTITION"
# 检查挂载结果
if [[ $? -eq 0 ]]; then
echo "成功挂载 /dev/$DISK_PARTITION 到 $MOUNT_POINT"
else
echo "错误:挂载失败!请检查分区是否存在或路径权限。"
fi