Niraj Radadiya:
Hello, when I try to redirect command output I am getting this permission denied error. Can anybody explain me why am I getting that?
Aaron Lockhart:
@Niraj Radadiya: Redirection is done by the shell, and doesn’t inherit sudo
permissions from your sudo diff
command.
Aaron Lockhart:
Try issuing sudo -i
to become root
and then issue the diff
command and redirection.
Niraj Radadiya:
okay. Can I also try to add sudo after > ?
Aaron Lockhart:
No. The redirection operator doesn’t function that way. If you’re wanting to use sudo
, you would need to also call a shell using sudo
.
sudo bash -c diff /opt/dir1 /opt/dir2 > /opt/onlyindir2.txt
.
Niraj Radadiya:
okay, thank you.
Aaron Lockhart:
My pleasure!