Can I pipe the stout from a download/install to a log file

Hi all,

I'm curious how to take the output from the console during a download and pipe it into a new file so I can view it later. That way I can download something, leave, and review that .log file to see if everything went okay.

For example:

sudo apt-get install htop | <magic code here > htopInstall.log

Can't you just do: sudo apt-get install htop > htopInstall.log ?

1 Like

Yeah theres a few ways you could do it. I'm stuck in windows at the moment so I couldn't test it, but I'm pretty sure you can do

 <commands> | </file/directory/log/thing>
1 Like

@FaunCB

$ sudo apt-get install htop | ~/InstallLogs/htopInstall.log

Returning: $ htop.log: command not found

// not sure if typing file path like that is causing error

@chmod000

$ sudo apt-get istall htop > htopInstall.log

Command works. It directs all output to file, none to console.

Hopefully, not asking for too much... could I display it to both console and the file?

I use the command tee to do this. In your case I would change the command to this:

$ sudo apt-get install htop | tee htopInstall.log

This should display it to both the consoel and file. You may want to read the man page for tee.

2 Likes

Are you sure thats what i says and thats the command you ran? i ask because the command says htopInstall.log and you've said it coudlnt find htop.log

The reason that isnt working is being its trying to run htopInstall.log not output data to it.

You probably want this

sudo apt-get install htop | tee ~/InstallLogs/htopInstall.log

Remembering to make sure ~/InstallLogs exists

edit: see man tee for more info

beat me to it @heffjos

2 Likes

It should say Returning htopInstall.log : command not found

Here is the proper sequence:

$ pwd

/home/cotton/InstallLogs

$ ls

htopInstall.log

$ sudo apt-get install htop | htopInstall.log

htopInstall.log: command not found

$sudo apt-get install htop | ~/htopInstall.log

bash: /home/cotton/InstallLogs/htopInstall.log: Permission denied
E: Could not get lock /var/cache/apt/archives/lock - open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/cache/apt/archives/

@Eden
There's an error with tee on my machine.

$ sudo apt-get install htop | tee htopInstall.log
[installs program]
...
The following NEW packages will be installed:
htop
0 upgraded, 1 newly installed, 0 to remove and 13 not upgraded.
E: Could not get lock /var/cache/apt/archives/lock - open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/cache/apt/archives/

That's not an error with tee, the error comes from apt-get, I think it means that apt is busy.

2 Likes

All is well!

Thanks @chmod000 @Eden @FaunCB @heffjos this is very helpful.

1 Like