如何用Bash将MacOS的Documents目录移回默认位置?
Hey there! Let's walk through this step by step since you're still getting comfortable with Bash. First, let's recap what the original script did—this is key to fixing this right:
The original script moved your actual Documents folder into
Box Sync, then created a symbolic link (that's theln -spart) at your old/Users/$USER/Documentspath. This link acted like a shortcut: any time you saved something to "Documents", it actually went to the folder inside Box Sync.
The Problem With Your Current Script
If you run your existing mv command directly, it'll cause issues. Right now, /Users/$USER/Documents is a soft link pointing to /Users/$USER/Box Sync/Documents. Trying to move the real folder into the link would either throw an error (since you can't move a folder into itself indirectly) or accidentally mess up your file structure.
Correct Steps to Fix This
Follow these commands in order to safely move everything back:
Delete the symbolic link first (critical—don't skip this!)
rm /Users/$USER/DocumentsImportant: Don't add
-rhere!-rwould delete the actual files in Box Sync, not just the shortcut. Since this is a soft link, a simplermremoves only the link itself.Move the real Documents folder back to your home directory
mv /Users/$USER/Box\ Sync/Documents /Users/$USER/If you get a permission error here, you can add
sudoat the start—but only if necessary. Most user folder operations don't require root access unless the original script messed up permissions.Verify it worked
Run this command to check if/Users/$USER/Documentsis now a real folder (not a link):ls -l /Users/$USER/DocumentsLook at the first character in the output:
dmeans it's a real directory (good!)lmeans it's still a link (double-check step 1 if this happens)
Quick Notes
- You don't need to keep
sudoin your script unless you hit permission blocks. Usingsudounnecessarily can cause permission issues down the line. - If you ever need to check if a path is a link again,
ls -lis your go-to tool—it'll show you where the link points if it's one.
内容的提问来源于stack exchange,提问作者deefo

