How can I run
sudo apt-get install by BOTH seeing the process of installation (long in my case) and saving its output into a text file ?
You can use the
tee command to accomplish this.
sudo apt-get install someapp 2>&1 | tee ~/someappInstall.txt
Look here for more info, or execute
Note: As others have mentioned,
2>&1 is necessary to redirect STDERR to STDOUT to catch any errors. See this StackOverflow question for a good explanation of what
2>&1 actually does.
tee will do the job as required.
To capture the output into a file, use:
sudo apt-get install your_software | tee log_file.txt
This will only capture the output, but not any error messages. If you would also like to record error messages, modify the command to be:
sudo apt-get install your_software 2>&1 | tee log_file.txt
One of the beauty of apt-get (and APT in general) is that they store log files for almost everything, even the terminal output of any command that you run trough, in the
/var/log/apt. For example, this is the last entry in my
Log started: 2014-06-20 16:46:08 (Reading database ... 252472 files and directories currently installed.) Removing xdotool (1:3.20130111.1-3.1) ... Processing triggers for man-db (220.127.116.11-1) ... Log ended: 2014-06-20 16:46:33
Now, comparing with the actual output:
➜ ~ sudo apt-get remove xdotool Reading package lists... Done Building dependency tree Reading state information... Done The following package was automatically installed and is no longer required: libxdo3 Use 'apt-get autoremove' to remove it. The following packages will be REMOVED: xdotool 0 upgraded, 0 newly installed, 1 to remove and 2 not upgraded. After this operation, 135 kB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 252472 files and directories currently installed.) Removing xdotool (1:3.20130111.1-3.1) ... Processing triggers for man-db (18.104.22.168-1) ...
It saved me several lines that are not relevant in most cases, and it does automatically. So, you don't need any extra command to do what you want to do, apt-get does it for you.