Save console output into a file:
tee command - read from standard input and write to standard output and files.
It automatically creates file and save, all the output of cmd
ps -ax into a file named as
processes_info in the same folder from where the cmd has run.
user@admin:~$ ps -ax | tee processes_info
script command - make typescript of terminal session.
user@admin:~$ script my_console_output.txt
This creates a file named as
my_console_output.txt and will open a subshell and records all information through this session.
After this, script get started and whatever the console output, it will get stored in the file
my_console_output.txt; unless and until the script ends when the forked shell exits. (e.g., when the user types
exit or when CTRLD is typed.)
user@admin:~$ script -c "ps ax" processes_info.txt
it starts the script;
creates the file
stores the console output into the file;
end (close) the script.
script -c 'echo "Hello, World!"' hello.txt