Hacker News new | ask | show | jobs
by ptx 1043 days ago
Because the expansion of the wildcard needs to happen with the privileges granted by sudo. If you just ran "sudo rm ..." the expansion would be done by the current shell, which doesn't have the required privileges.
3 comments

I don't know anything about MacOS. Normal users don't have r-x on /Users ? How do they access their own /Users/whatever homedir then?
Normal users have r-x on /Users, but for that wildcard to work, they would need r-x on /Users/foo, /Users/foo/Library, and /Users/foo/Library/LaunchAgents, for every "foo" user in the system.
For that exact command, yes. But if `/Users/*` by itself can be expanded without root you can construct the list of files to delete without needing the `zsh -c`. Eg `for d in /Users/*; do sudo rm -f "$d/Library/LaunchAgents/NightOwlUpdater.plist"; done`

It's a minor point overall. I was just checking if MacOS had something else going on with its file permissions.

Pardon, but with double quotes, is'nt the expansion going to be done by the current shell anyway?
globs aren't expanded in double quotes (not in bash or zsh, at least).
Oh, makes sense. Thanks.