0

I'm porting a program from Linux and Windows to macOS, and we use /usr/tmp, I can switch to /usr/local, but it puzzles me why not root can create a directory there that I can chown and use with my program.

$ sudo whoami
root
$ whoami
mobj
$ sudo mkdir /usr/tmp
mkdir: /usr/tmp: Operation not permitted
$ ls -ld /usr/
drwxr-xr-x@ 11 root  wheel  352 Nov  2 23:44 /usr/
$ sudo mkdir /usr/local/tmp
$ sudo chown mobj:dist /usr/local/tmp
$ ls -ld /usr/local/tmp
drwxr-xr-x  2 mobj  dist  64 Nov 23 12:07 /usr/local/tmp
5
  • See also apple.stackexchange.com/questions/388236/…
    – lhf
    Commented Nov 23, 2023 at 12:58
  • @lhf Not sure this still works with SSV.
    – nohillside
    Commented Nov 23, 2023 at 14:06
  • Being root doesn't have the "god" status like on other Unixes, and confers very few benefits over an admin user with sudo. And leaves all your doors open.
    – benwiggy
    Commented Nov 23, 2023 at 15:13
  • 2
    On a Unix, you should be using /usr/local/bin anyway for your binaries and $TEMP for wherever you are keeping temporary files. Commented Nov 23, 2023 at 15:56
  • I have used many Unixes and have never had a temporary director in /usr/tmp - the correct directory now and especially on macOS is use the environment variable $TMPDIR - and older way that usually works but be careful on multi user machines is /tmp. Windows often has a varible but he correct way is to call the Windows API to get the temp directory - as it is for macOS and POSIX only use the environment variable if you language has a poor library like bash - any hard coded directory is a bug.
    – mmmmmm
    Commented Nov 23, 2023 at 20:11

1 Answer 1

6

Apple restricts changes to a number of directories, including usr.

See: https://support.apple.com/en-us/102149

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .