I am trying to insert some text in a file in the following way
sudo echo "abc-abc/abc/abc" >> /etc/portage/make.conf
but it give me the error Permission denied
although I am using sudo command
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
In that command line, your shell opens the
/etc/portage/make.conf in append mode, makes it the stdout of a new process and runs
sudo in that new process. It's not
echo that open the file, it's your shell which is running with your credentials.
You'd need the file to be opened by the command started as root. So it could be:
sudo sh -c 'echo "abc-abc/abc/abc" >> /etc/portage/make.conf'
echo "abc-abc/abc/abc" | sudo tee -a /etc/portage/make.conf > /dev/null