How to use sudo to view a hidden directory?

Paul Sladen ubuntu at
Thu Sep 29 11:59:00 UTC 2011

On Wed, 28 Sep 2011, Knute Johnson wrote:
> But since you responded, how would you change directories to one that 
> you can't read with your user privilege

  $ man sudo | grep -A3 -B1 'sub-shell'

  To make a usage listing of the directories in the /home partition.
  Note that this runs the commands in a sub-shell to make the cd and file
  redirection work.

    $ sudo sh -c "cd /home ; du -s * │ sort -rn > USAGE"

But it's very rare in practice (in my workflows) that I'd need to do
this;  mostly a:

  sudo ls -l /root
  sudo cp -a /root/hidden /root/other-hidden

is sufficient.  If you need to cat into a root owned file, you can:

  echo asdf | grep asdf | sudo tee -a /root/created-as-root

all of these have the massive advantage of being logged and audited.


More information about the ubuntu-users mailing list