0

I learnt that a tee command will store the STDOUT to a file as well as outputs to terminal.

But, here the problem is every time I have to give tee command, for every command I give.

Is there any way or tool in linux, so that what ever I run in terminal, it should store the command as well as output. (I used tee command in MySQL, where it will store all the commands and outputs to a file of that entire session. I am expecting a tool similar to this.)

Edit: When I run script -a log.txt, I see ^M characters as well as ^[ and ^] characters in log.txt file. I used various dos2unix, :set ff=unix, :set ff=dos commands, but they didn't helped me in removing these ^[, ^] characters. Is there any method, I can directly get the plain text file (with out these extra chars).

OS: RHEL 5

Rajasekhar
  • 894
  • 5
  • 13
  • 25
  • [`man script`](http://unixhelp.ed.ac.uk/CGI/man-cgi?script) – tripleee Sep 04 '14 at 06:39
  • possible duplicate of [Piping an interactive session to a file](http://stackoverflow.com/questions/18812098/piping-an-interactive-session-to-a-file) – tripleee Sep 04 '14 at 06:41
  • Most of the desktop consoles like 'konsole' in KDE and `gnome terminal` provide an option to save the entire scrollback for the terminal. For example the `Edit` menu in `konsole` provides the option to `Save History As...` which will prompt for a filename and save all lines to a file. Your `~/.bash_history` file should already have all the commands. If you want to do this on a `per-command` basis from within a script -- then you are stuck with `tee` if you want screen output in addition to redirection to a file. – David C. Rankin Sep 04 '14 at 07:10
  • David, in my terminal there is no option to save the session. I am using RHEL 5 – Rajasekhar Sep 05 '14 at 12:00

2 Answers2

1

You can use script command which writes everything on file

script -f log.txt
Rahul R Dhobi
  • 5,668
  • 1
  • 29
  • 38
-2

you could use aliases like such alias ls="ls;echo ls >>log" so every time you run ls it runs echo ls >>log too. But script would probably be better in this case, just dont go into vi while you are in script.

nana
  • 1
  • 1