I’m using Ubuntu 14.04. I’m having trouble clearing out a file. I’m getting permission denied even though I’m using sudo. Here’s what’s happening …
myuser@mymachine:~$ sudo chmod 755 /var/log/unicorn/unicorn.log
myuser@mymachine:~$ sudo echo '' > /var/log/unicorn/unicorn.log
-bash: /var/log/unicorn/unicorn.log: Permission denied
myuser@mymachine:~$ ls -al /var/log/unicorn/unicorn.log
-rwxr-xr-x 1 rails root 304746186 Dec 31 15:08 /var/log/unicorn/unicorn.log
What evil demonic possessions have taken over and how can I conquer this crazy file?
sudo echo '' > /var/log/unicorn/unicorn.log
, you're running theecho
command as root but redirecting its output as your own (non-root) user. See When using sudo with redirection, I get 'permission denied'. – Eliah Kagan Dec 31 '16 at 20:14