ubuntu - Why I can I edit but not append a unix file -


feeling pretty dumb. same user i able edit file via vi, permission errors when appending file. what doing wrong. append file!

ls -alt /var/log drwxr-xr-x 11 root      root     4096 may 14 01:20 . -rw-rw-r--  1 root      root        6 may 14 01:20 money-worker.log  sudo echo "hello" >> /var/log/money-worker.log -bash: /var/log/money-worker.log: permission denied  whoami ubuntu 

i running ubuntu 12.04, , sshing in

love tips. guys!

because:

sudo echo "hello" >> /var/log/money-worker.log 

means:

( sudo echo "hello" ) >> /var/log/money-worker.log 

not:

sudo ( echo "hello" >> /var/log/money-worker.log ) 

in other words, appending being attempted shell before sudo runs. shell (attempt to) open file append "attach" sudo stanadard output.

as workaround, try like:

sudo bash -c 'echo "hello" >> /var/log/money-worker.log' 

which run entire bash-with-arguments-and-redirections under control of sudo.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -