Skip to main content
3 of 3
The pronoun 'I' should be capitalized; English contractions use apostrophes.
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 265

Using SUDO to execute a general command inside a non-accessible directory

I want to grep something inside a directory. But the user doesn't have permissions in the directory. Because of some reasons, I am not allowed to change permissions, group or owner. Just want to know I can access that directory by some entry in the sudoers file.

grep -r "some phrase" /path/to/restricted-dir

Is there any way to execute the above command using sudo?