Open "Opt" folder with Terminal on Mac
Solution 1
/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
https://apple.stackexchange.com/questions/119230/what-is-standard-for-os-x-filesystem-e-g-opt-vs-usr
Why is there a /usr/local/opt directory created by Homebrew and should I use it?
Solution 2
- 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;
Leia_Organa
Junior Software developer at an IT company. Languages: HTML, CSS, Ruby on Rails, JavaScript, Java
Updated on March 20, 2021Comments
-
Leia_Organa over 3 years
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 almost 8 yearsThank you for the suggestion! I tried the sudo command and all I got was "illegal user name". Any suggestions for that?
-
Cam_Aust almost 8 yearsSuggestion 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?
-
Feneric almost 8 years@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 almost 8 years@Leia_Organa Did this work for you? If not, please tell me how it failed and I'll modify it so it does work.
-
hhh over 5 yearsDoes 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. -
Feneric over 5 years@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 unix.stackexchange.com/questions/11544/… for a more complete explanation of the differences. -
J-A-S over 3 yearsMay 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 over 3 yearsAhh, just got to know that CMD + shift + . is the shortcut for showing/hiding hidden files :)
-
J-A-S over 3 yearsAnd change the defaults... to NO should undo it