script
command is appropriate when you want to save a terminal session to a file and display it later. When you call script
it launches your shell, and when you are done, just type in exit. Everything will be in typescript
file unless you specify otherwise.
For instance,
xieerqi:$ echo "Hello, Karl Wilbur"
Hello, Karl Wilbur
xieerqi:$ date
2015 10 27 11:38:15 MDT
xieerqi:$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 115247656 80939384 28430924 75% /
none 4 0 4 0% /sys/fs/cgroup
udev 2914832 4 2914828 1% /dev
tmpfs 585216 1100 584116 1% /run
none 5120 0 5120 0% /run/lock
none 2926072 328 2925744 1% /run/shm
none 102400 52 102348 1% /run/user
xieerqi:$ exit
Script done, file is typescript
xieerqi@eagle:~$ cat typescript
Script started on 20151027 113755
xieerqi:$ echo "Hello, Karl Wilbur"
Hello, Karl Wilbur
xieerqi:$ date
2015 10 27 11:38:15 MDT
xieerqi:$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 115247656 80939384 28430924 75% /
none 4 0 4 0% /sys/fs/cgroup
udev 2914832 4 2914828 1% /dev
tmpfs 585216 1100 584116 1% /run
none 5120 0 5120 0% /run/lock
none 2926072 328 2925744 1% /run/shm
none 102400 52 102348 1% /run/user
xieerqi:$ exit
Script done on 20151027 113818
There may be control characters in the typescript file though ,such as from the ls
comand, so use cat typescript | col -b > outputfile.txt
command to redirect clean output to file