How to record complete Linux session/terminal logs to a file ?
Today in this post, we will see how to record complete terminal/session logs in a file in Linux.
1. Run the “script” command with filename in which to record.
[ngeuser@ngelinux001 tmp]$ script testfile1 Script started, file is testfile1
2. Now do your activity.
[ngeuser@ngelinux001 /tmp]$ date Wed Jan 4 22:02:57 IST 2023 [ngeuser@ngelinux001 /tmp]$ uname -a Linux ngelinux001 2.6.32-431.11.2.el6.x86_64 #1 SMP Mon Mar 3 13:32:45 EST 2014 x86_64 x86_64 x86_64 GNU/Linux [ngeuser@ngelinux001 /tmp]$ echo "hello" hello [ngeuser@ngelinux001 /tmp]$ [ngeuser@ngelinux001 /tmp]$ exit Script done, file is testfile1 [ngeuser@ngelinux001 tmp]$
Now when we run Ctrl+D, or exit the session, the logs will be written to the file.
3. Check out the recorded activity.
[ngeuser@ngelinux001 tmp]$ cat testfile1 Script started on Wed 04 Jan 2023 10:02:54 PM IST [ngeuser@ngelinux001 /tmp]$ date Wed Jan 4 22:02:57 IST 2023 [ngeuser@ngelinux001 /tmp]$ uname -a Linux ngelinux001 2.6.32-431.11.2.el6.x86_64 #1 SMP Mon Mar 3 13:32:45 EST 2014 x86_64 x86_64 x86_64 GNU/Linux [ngeuser@ngelinux001 /tmp]$ echo "hello" hello [ngeuser@ngelinux001 /tmp]$ [ngeuser@ngelinux001 /tmp]$ exit Script done on Wed 04 Jan 2023 10:03:14 PM IST [ngeuser@ngelinux001 tmp]$
As we can see above, the whole activity is recorded in the file.