I created a file with sudo like this:

sudo touch abc.txt

Which understandably set the owner to root. Now when I try to edit the file via vi using sudo, it works:

sudo vi abc.txt #works

But when I do something like

sudo cat > abc.txt

It gives me the permission error.

marked as duplicate by Kusalananda linux Feb 22 at 10:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Browse other questions tagged or ask your own question.