1

I'm trying to list the contents of the whole apropos (makewhatis) database with the following command but I keep getting Permission denied.

sudo -s apropos . > touch thedatabase

-bash: touch: Permission denied


sudo -s apropos . > thedirectory

thedatabase: Permission denied


apropos . > touch thedatabase


All of these result in some form of Permission Denied. How do I get around this or what is the more elegant way of doing this?

  • I'm not sure what you're trying to do, but have a couple of observations that may help: 1) The redirect is interpreted in the current shell, not the sudo shell, so if you're in a directory you can't write to as a normal user, that could cause a permission denied; 2) the first word after the redirect is the file to redirect to, so the first example is equivalent to sudo -s apropos . thedatabase > touch, and similarly the last example. Maybe just try apropos . >/tmp/ap.out, you should be able to write to /tmp. – blm Oct 9 '15 at 16:40
  • @blm First of you were right, my problem was that I was in a non-authorized directory. To be clear, the redirect is> correct? And how does your example of of putting thedatabase before > touch make sense? I don't think I have a solid grasp of the ordering that these things can be in. Thank you! – inthenameofmusik Oct 9 '15 at 16:44
  • My example with thedatabase before > isn't really an example, it's what your first example is doing. While redirects are normally put at the end of a command, they don't have to be, For example, echo hello >echo.out is how one would normally write a command to echo a line containing "hello" to the file echo.out, but echo >echo.out hello and >echo.out echo hello do the same thing. So in your first example, the shell sees > touch and treats that as a redirect to the file touch, then when it sees thedatabase, it's treated as just another command argument. – blm Oct 9 '15 at 16:53
  • awesome, that makes perfect sense. thank you very much. – inthenameofmusik Oct 9 '15 at 17:14
1

I'm not sure how to do what you are asking. Looking into that now, but I know how to get around the permissions problems you are having with sudo.

Your syntax is wrong for sudo, the shell redirection ">" is happening without elevated privelleges. Try wrapping in quotes like this:

sudo -s 'apropos . > touch thedatabase'

You must log in to answer this question.

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