0

In Fedora, some people recommend adding some config values to /etc/dnf/dnf.conf. For example:

fastestmirror=True
max_parallel_downloads=10
defaultyes=True

I'd like to automate these config updates on a new system from a script in my dotfiles with a command like this:

sudo echo 'fastestmirror=True' >>/etc/dnf/dnf.conf

But I get a permission denied error when I try from terminal, even with sudo. I think maybe its because the file is owned by the root user? How can I make this work?

echo
  • 111
  • Would you please edit your question to include the command you entered in the terminal, and the error message that you received? – Sotto Voce Aug 07 '22 at 04:06
  • 2
    does this help? https://unix.stackexchange.com/questions/1416/redirecting-stdout-to-a-file-you-dont-have-write-permission-on – thrig Aug 07 '22 at 04:08
  • yep that's exactly what I needed, thanks! I'll create an answer for the question – echo Aug 07 '22 at 04:22

1 Answers1

1

In the comments user thrig posted this link that describes using tee: Redirecting stdout to a file you don't have write permission on

That link had a link to this post that discussed tee plus several other options: https://stackoverflow.com/questions/82256/how-do-i-use-sudo-to-redirect-output-to-a-location-i-dont-have-permission-to-wr/82278#82278

Of the options, I decided to go with

sudo sh -c 'echo "fastestmirror=True" >>/etc/dnf/dnf.conf'

(and I verified in terminal this works)

echo
  • 111