How can I use volume names with a space in them with tmutil in Mac OS?

I am trying to write a simple electron script to switch between my different time machine backups, but I have gotten somewhat stuck because tmutil keeps throwing errors when a volume name has a space in it, just as in

sudo tmutil removeexclusion -v /Volumes/MacOS Mojave /Volumes/MacOS Mojave: The operation couldn’t be completed. Invalid argument 

OK, that one was still pretty obvious, but now, what about

sudo tmutil removeexclusion -v "/Volumes/MacOS Mojave" /Volumes/MacOS Mojave: The operation couldn’t be completed. Invalid argument 

or even

sudo tmutil removeexclusion -v /Volumes/MacOS\ Mojave /Volumes/MacOS\ Mojave: The operation couldn’t be completed. Invalid argument 

man tmutil doesn't really go into any details about spaces or special characters in their documentation on those commands, escaping characters and quoting the paths are both ways to do this usually, but apparently not in this case. Quotes work when I use them on volume names without spaces, but that is not really the point here.

10

1 Answer

So, thanks to some valuable help from the commenters, I was able to determine, that the partition with the space in the name was also my root partition, and as that to tmutil only visible as /. The first giveaway for that was running a ls -al /Volumes, which gave an output of

lrwxr-xr-x 1 root wheel 1 26 Aug 13:22 MacOS Mojave -> / 

At first I didn't think too much of it, after all it's just an alias, right?

But when I ran

sudo tmutil addexclusion -v "/Volumes/MacOS Catalina" 

on another partition with a space in it, which just happened to not be my root partition at the time, I did not get an error, thus eliminating the theory that the error was caused by a space at all. And then, running

sudo tmutil addexclusion -v "/" 

succesfully excluded "MacOS Mojave", as I could see in TM's preferences pane.

Thus, in conclusion, tmutil works wonderfully with Volumes which have spaces in their names, but you have to be conscious of the root partition, which will not be addressed under its name, but as /. Both of those details just happened to have conspired to hide behind a smokescreen that shouted "no spaces allowed".

To answer the question as asked originally: Yes, you address names with a space either enclosed by " " or escaped with a \ .

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like