sch sch - 18 days ago 5
Linux Question

Proper use of '/opt' folder on linux

Linux System:

Ubuntu 14.04 LTS


I copy some app (like
xxx
) to the
/opt
folder to be used also by another user-accounts. Then to start it I use:


sudo /opt/xxx_folder/xxx


(of course, links to /usr/local/bin or /usr/bin, etc.) to start it;

Problem: I'm storing the results/projects of the app to my local folder ( like
/home/myuser/xxx_data
). And of course the folder and it's data
xxx_data
belongs to
root
(not
myuser
). So I have to change the owner every time I want to edit those files using another app not as a root.

Question: is there a way to install an app
xxx
to
/opt
so, that I don't need to start them as a root?

OR maybe you see another way to solve this 'root-user-problem?'

Answer

You can add execute permission to any file like this.

sudo chmod +x file.sh

If you want to do that for all files in that folder try this:

sudo chmod +x /opt/*

Note the +x just adds execute permission to your logged in user. I think all users have read (+r) by default so if you also want to add write permission:

sudo chmod +xw /opt/*

Personally I keep all my custom scripts in a bin folder e.g. /opt/bin/ and just do:

sudo chmod +x /opt/bin/*

To run the script without the full path add the bin or full opt folder to your path by adding the following to ~/bashrc file:

PATH=$PATH:/opt/bin

If you don't end up using the bin folder, edit above to be /opt instead of /opt/bin.