Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 384
  • Last Modified:

send top command output to a text file ?

Hello, I am using an Ubuntu 12.04 Linux system and am trying to capture the output of the top command using the following command:

 sudo top -n 1 -b > top-output.txt

when I run this command I get the following error, can someone let me know what I need to do to avoid this error and be able to capture the output as a text file?

-bash: top-output.txt: Permission denied
 

Thank you,
A
0
aej1973
Asked:
aej1973
1 Solution
 
TintinCommented:
sudo will run top with root privs, but any file redirection will occur as the userid invoking the command.

Unless sudo has suid disabled, then there's no need to use sudo.

Just redirect the output to a directory you have write permission for, eg:

top -n 1 -b >/tmp/top-output.txt
0
 
aej1973Author Commented:
Thank you, it works.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now