2

I love Ubuntu, and I used it for a long time before Unity. I loved it. Now I have a Mac...

I have some habits remaining from my Ubuntu workflow.

Sometimes I like to open folders from terminal directly, on Ubuntu I would do gksudo gnome-open /folder or open files for editing in my favorite editor sudo gedit /file.php

So how is it done on OS X?

I use Sublime Text 2 as my main editor, so is it possible to use Sublime like gedit from terminal?

P.S.: Quick Google search found me open . for opening folders. But will sudo work like gksudo on Ubuntu?

1 Answer 1

2

will sudo work like gksudo on Ubuntu?

No, it won't. To open the folder you're currently in, all you really need to do is type open .. If you want to open a file, the same applies.

If you however need root permissions for a file, then you need to tell open which application exactly to run. Normally, you would do this with open -a NameOfApplication, like open -a TextEdit, but TextEdit will still be run without root privileges if you call sudo open -a TextEdit. This is because the process of opening is deferred from open to a service in OS X that won't run as root.

The trick is to run the actual executable of the application you want to open with sudo. For example:

sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /path/to/file

If you're lazy and want to repeat doing that, you could create an alias in your shell.


is it possible to use Sublime like gedit from terminal?

Much easier:

ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl

That requires ~/bin/subl to be in your PATH. Otherwise:

sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /bin/subl

Then just run subl /path/to/file.

0

You must log in to answer this question.