I want to append the line "include /etc/nginx/tcpconf.d/*;" to the file /etc/nginx/nginx.conf.

When I did run the below command, it failed -

$ sudo cat "include /etc/nginx/tcpconf.d/*;" >> /etc/nginx/nginx.conf
-bash: /etc/nginx/nginx.conf: Permission denied

When I did the same with below bash command it is successful -

$ echo "include /etc/nginx/tcpconf.d/*;" | sudo tee --append /etc/nginx/nginx.conf
include /etc/nginx/tcpconf.d/*;

Any idea why the previous command is not working?

  • 2
    First of all, you should use echo and not cat. Secondly, the sudo in the first case runs cat and not to the whole pipeline. – Kapil Apr 16 '19 at 2:29

Browse other questions tagged or ask your own question.