0

For a homework assignment I have to execute some commands and report the results.

But when I try du /var > tmp.txt it says I am not allowed to access tmp.txt.

I have tried to use a different name for the file but no different results, I have tried to add the text file to the Computer folder in the GUI but I am unable to do that too.

I am in the sudo group, sudo echo ok returns ok

My question: why can't I add a simple txt file to the Computer folder and how can I do this?

2
  • @snoop the error is in Dutch, but translate its simply " Bash: tmp.txt: Access denied"
    – Vahx
    Oct 3, 2015 at 12:09
  • Yeah, then its a access issue on that particular path.
    – snoop
    Oct 3, 2015 at 12:11

2 Answers 2

3

You may be in a folder where your user doesn't have permissions.

Try du /var > ~/tmp.txt to write the file to your home directory, you should have write permission there.

3
  • This works, thank you. it seems that being in the sudo group is not enough to have full authorization of everything. Not sure if i can work around that or how to log in as root as default.
    – Vahx
    Oct 3, 2015 at 12:08
  • 1
    Is is strongly discouraged to log in as root as default! Use sudo to execute commands as root.
    – Jan
    Oct 3, 2015 at 12:12
  • I understand the security reasons, but this is all on a virtual machine, which i only use for school purposes atm.
    – Vahx
    Oct 3, 2015 at 12:13
2

When you redirect output, the sudo is not applied to the output file.

You can do it by

du /var | sudo tee tmp.txt

or

sudo -i
du /var > tmp.txt
exit
3
  • @terdon Why was sudo su changed to -i? this allowed me to log in as root (i think) and write the txt file where i wanted to originally
    – Vahx
    Oct 3, 2015 at 12:12
  • 3
    @Vahx both sudo -i and sudo su do essentially the same thing. There is just rarely, if ever, any good reason to run sudo su since that's running two processes and is just a more complex way of doing sudo -i. See here for more.
    – terdon
    Oct 3, 2015 at 12:18
  • I agree that sudo -i is a bit better.
    – Pilot6
    Oct 3, 2015 at 16:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .