Hello, How do we redirect/write the output to a file in the exam? I faced ‘permi . . .

Vikram:
Hello, How do we redirect/write the output to a file in the exam? I faced ‘permission denied’ issue.

Tej_Singh_Rana:
Hello, @Vikram
Did you try from the root user?

Vikram:
as root user, I could not run the kubectl commands. I tried a couple of options with sudo and sudo -i, but wasn’t successful there. In the end I manually opened the files in vi as root user and inserted the answer. Wasted some of the time. What is the right approach?
Thank you for your response.

Tonnie I:
<file> | sudo tee -a <to_path>

Tonnie I:
e.g: kodekloud_file | sudo tee -a /opt/k8s.txt

Vikram:
TY @Tonnie I

Tonnie I:
You are welcome