0

I am using savefig() and saveas() functions to save .fig and .jpg files resp. in MATLAB (R2015a, Ubuntu 14.04, personal computer, single account). However, the owner of files being generated is root. I want the owner to be my user account.

I can use chown in terminal to later obtain the ownership, but I want that to happen directly from MATLAB, i.e. at the time of file creation.

Also, this problem was not occurring before. I just made a fresh installation of OS and all software, and this behaviour started happening.

user3342981
  • 85
  • 2
  • 7
  • 1
    aren't resulting file permissions the ones of the user that started the application? hence why is the application running under root? How are you starting Matlab? Also: where are you saving the files? Can you give an `ls -la` of the directory where you saved files? – Gunther Struyf Jul 31 '16 at 19:03
  • Running MATLAB R2015b under Ubuntu 14.04, I get `-rw-r--r--` permissions for the file, owned by a normal user, not root. Of course, not running MATLAB under root user. – Matthias W. Jul 31 '16 at 20:25
  • @GuntherStruyf I was running the application as root, particularly I was using the command `sudo matlab`, which is the reason why this was happening. I am writing answer to clarify everything. – user3342981 Aug 01 '16 at 13:05

2 Answers2

0

I agree with previous users that this is more likely an issue of what user starts MATLAB to begin with.

A quick and dirty way of solving this issue is using the system command.

system('chown user:group DIRTOSAVEDFILE');

or

system(sprintf('chown %s:%s %s',USERSTRING, GROUPSTRING, SAVEDFILEDIR));

Please reconsider using system if you plan to distribute this code as the systemcommand gives access to to /bin/sh (maybe even with root privileges depending on how MATLAB is started).

Skogsv
  • 494
  • 3
  • 14
0

I have figured out what I was doing wrong.

I was running MATLAB using the command sudo matlab, which is why the files being saved to disk had the ownership of root. The reason why I was running MATLAB as root was because simply using matlab in terminal was not working for me. Particularly, MATLAB gave JAVA exception error: "Error starting desktop". To resolve that error, I had to get the ownership of MATLAB's preferences directory, which is ~/.matlab/R2015a. I did sudo chown -R username:username ~/.matlab/R2015a/ to get the ownership. Now, I can run MATLAB without sudo as well as the files being generated have also my ownership. I used the following link to solve my ownership problem:

http://in.mathworks.com/matlabcentral/answers/50971-matlab-r2012b-java-exception-error-starting-desktop

Thanks for the comments and answers. I should have done more research I guess.

user3342981
  • 85
  • 2
  • 7