Redirect output to a file permission denied? Redirect output to a file permission denied? unix unix

Redirect output to a file permission denied?


The privilege elevation only applies to the curl process (and, in the second example, the child shell) itself, not to your (parent) shell, and therefore not to the redirection.

One solution is to do the redirection within the child shell itself:

sudo bash -c "curl $LINK >a.txt"

Another, fairly idiomatic option is to use tee:

curl $LINK | sudo tee a.txt >/dev/null

For curl specifically, you can also make the process itself write to the file directly:

sudo curl -o a.txt $LINK


I ran into the same problem and it's because the folder of a.txt isn't writable to you. Either chmod/chown it or put it to a writable folder will solve the problem.

Hope this helps!