Task:
While installing or debugging a task in Linux, previous session
history will helps a lot to review the work what we have done when if
any error occurs. For this, we need to store the entire session action
and its output into a file or some where.
Solution:
This can be achieved by more commands depends of the user requirement.
- Command wise
- Using output redirect
This is the simplest command used to save our console outputs into a file.
$ ls -al > out.txt
$ ls -al >> out.txt
Here, '>' used to redirect the output to a file and '>>' is used to append the new output with existing one. Main drawback of this command is, the console will not display anything. All the outputs will goes to file instead of console. - Using 'tee' command
This command overrides the drawback of previous method. This will send the copy of the output only to the file. So that the normal output is displayed in console as it is.
$ ls -al |tee out.txt
This will erase the previous contents while writing new one. To avoid this use the following syntax to append
$ ls -al |tee -a out.txt
Main drawbacks of previous two commands is, we need to give the tailing commands (either > or tee) with each and every commands we are executing in that console.
- Session wise
In this method, the entire session from the start to end will be save given file. This contents will be written into the file once we close the terminal. - Using 'script' command
Run the following command before starting any execution in console to start recording.
$ script -a today.txt
Then do your usual work and once complete the tasks then quits the terminal and see the saved file contents like,
$ more today.txt
Note: This is tested under Ubuntu 11.10
No comments:
Post a Comment