0

A coworker who is no longer on my help desk team tested a redirect script on my MacBook that moved my home folders in to my Box Sync folder to sync those folders to the cloud.

An excerpt of the script he ran is as follows:

#!/bin/bash

home="/Users/$USER"

sudo mv $home/Documents $home/Box\ Sync/ && ln -s $home/Box\ Sync/Documents $home/Documents

I have a limited knowledge of Bash. I want to move the directory to its default location in the home folder (ex: /Users/$USER/Documents).

Would the correct way to do this be the following?

#!/bin/bash

home="/Users/$USER"

sudo mv $home/Box\ Sync/Documents $home/Documents

It seems simple enough but I don't know if I should do anything about the ln -s bit in the original script. I believe thats what links the original location to the new location. Please correct me if I'm wrong.

1 Answer 1

1

You are correct about the link. It simply created a link back to $home/Documents from the Box Sync folder so the other things in OSX (MacOS) using Documents will still work.

The move as is would simply overwrite the softlink (ln -s) and result in what you require.

If you want to be unreasonably safe, you can run :

rm $home/Documents

first. If it is already a directory it will not delete it without -r flag.

Sign up to request clarification or add additional context in comments.

2 Comments

Running the command to move the directory back to the home folder returned an invalid argument. Seems it did not want to overwrite the softlink. I removed deleted the softlink via rm first and ran the command again and it worked fine. Thank you!
FYI, I tried rm && mv and it didn't like it either. I suppose the commands have to be run separately.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.