3

So here is a simple question whose answer has proved elusive. I recently installed a folder that I need to add some files to. The folder is stored in the "opt" folder I thought it would be as simple as:

myusername ~/opt/foldername

But I can't seem to find "opt". I can view the files in Finder, but I need to create some files and I'd rather do that on the command line. Can anyone give me some tips for accessing it?

Leia_Organa
  • 1,894
  • 7
  • 28
  • 48
  • Are the files in `~/opt/foldername` (under your home folder) or `/opt/foldername`(under the root)? I've seen the latter used, and if that's the case just drop the `~`. – Feneric Jul 13 '16 at 02:19
  • They seem to be in Macintosh HD > opt > foldername. – Leia_Organa Jul 13 '16 at 02:25
  • 1
    You may find `opt` folder in `/usr/local/opt`, could you paste `ls /usr/local/opt`? – hhh Sep 30 '18 at 14:35

4 Answers4

7
  • The opt folder in OSX is hidden by default
  • To make it visible in Finder, you would need to run this command
    defaults write com.apple.finder AppleShowAllFiles YES;

and

    killall Finder /System/Library/CoreServices/Finder.app;
  • Next, goto Finder and there you would be able to see the opt folder when you click on Macintosh HD.

  • opt is accessible in the Terminal anyways.

  • The command you are using is wrong I suppose

    myusername ~/opt/foldername

~ represents the Home directory of the current logged in user. So you need to change it as:

    myusername$ cd /opt/



Note: To undo your changes, run these commands

    defaults write com.apple.finder AppleShowAllFiles NO;

and

    killall Finder /System/Library/CoreServices/Finder.app;
Sherwin Varghese
  • 481
  • 1
  • 5
  • 7
  • May I ask how to undo these after I've done with the opt folder? As after these hidden files are all over the place – J-A-S Nov 14 '20 at 06:13
  • 1
    Ahh, just got to know that **CMD + shift + .** is the shortcut for showing/hiding hidden files :) – J-A-S Nov 14 '20 at 06:17
  • And change the defaults... to NO should undo it – J-A-S Nov 14 '20 at 06:31
  • what if i have deleted that opt hidden folder? how can i recreate it ? – Irfan Yaqub Jan 31 '23 at 18:48
  • 1
    @IrfanYaqub If your user has Administrator privileges, it is possible. Open a terminal, run `sudo su` to get a root prompt, then run `open /` to open Finder or `mkdir /opt`. Also run `chmod 777` on the folder if you need other non-admin programs to write to it. – Sherwin Varghese Feb 02 '23 at 02:33
  • the `killall` seems to refresh the gui of finder to make `/opt` visible in the view. – Timo Jun 11 '23 at 12:13
  • There are two different hidden files in mac systems, one is `/opt and friends`, the secons is with dot before - in linux I only know of the second. – Timo Jun 11 '23 at 12:50
4

/opt folder is not apparently used in OSX instead /usr/local, for example, homebrew apparently uses /usr/local/opt instead of /opt. So if you need to place something originally in /opt directory, you may need to place it in /usr/local/opt in OSX.

It does not sound a good idea to mess up the file structure by creating a new root directory /opt. As mentioned in the second thread below "macOS is BSD-based and consequently I'd use /usr/local. Note that you can create a program directory and then symlink commands to /usr/local/bin.

I hope someone understanding OSX internals better could answer this.

Sources

  1. https://apple.stackexchange.com/questions/119230/what-is-standard-for-os-x-filesystem-e-g-opt-vs-usr

  2. Why is there a /usr/local/opt directory created by Homebrew and should I use it?

hhh
  • 50,788
  • 62
  • 179
  • 282
2
  • Open Finder
  • Press Command+Shift+G to open the globally folder finder
  • Input the following search: /usr/local/opt

OR

  • Click "Go"
  • open "Go to Folder"
  • Input the following search: /usr/local/opt
Saeed
  • 412
  • 5
  • 16
-1

Based on your description, use /opt/foldername on the command line instead of ~/opt/foldername. The first form will access a folder off the root, the second will access a folder within your home folder.

Depending on how it was set up it may or may not have provided you with write access. You can use sudo chown -R /opt/foldername username (where username is your username, if you don't know your username you can type whoami on the command line to find out) to claim ownership of the folder and everything that it contains if you lack write access.

Edit: because there was some confusion I'm pointing out here that /opt is as much a standard in UNIX-derived systems as /usr/local. They have slightly different purposes, but the difference is subtle (the full description is answered here https://unix.stackexchange.com/questions/11544/what-is-the-difference-between-opt-and-usr-local if you're interested). Using /opt is thus no less safe than using /usr/local, and it's generally preferred over using a combination like /usr/local/opt that doesn't get the distinction.

Feneric
  • 853
  • 1
  • 11
  • 15
  • Thank you for the suggestion! I tried the sudo command and all I got was "illegal user name". Any suggestions for that? – Leia_Organa Jul 13 '16 at 03:11
  • Suggestion Leia, when you can view the files in Finder, Command click on the folder name at the top to see where the folder containing the files is located. It is it your home files, or is it up the chain say in Computer HD? – Cam_Aust Jul 13 '16 at 08:15
  • @Leia_Organa you may not need that command at all; that's only if you can't write to that folder. Also, you can't use a literal "username", you have to use your own. If you don't know your own username, type `whoami` in the terminal. – Feneric Jul 13 '16 at 11:52
  • @Leia_Organa Did this work for you? If not, please tell me how it failed and I'll modify it so it does work. – Feneric Jul 14 '16 at 21:07
  • Does not sound a good idea to change the OSX original file structure? Minus removed unless clarified. How I understand this is that `/usr/local/opt` with bindings would be better option. – hhh Sep 30 '18 at 14:36
  • 1
    @hhh Like `/usr/local`, `/opt` has served as a standard location in UNIX-derived systems (which includes OSX) for site-specific "optional" installations. _Many_ packages assume it is being used this way, so the odds of Apple doing something to break this expectation are very low. Using `/usr/local/opt` is not safer than using `/opt`. See this answer https://unix.stackexchange.com/questions/11544/what-is-the-difference-between-opt-and-usr-local for a more complete explanation of the differences. – Feneric Sep 30 '18 at 15:29