Record Linux Terminal Commands

Introduction

This tutorial covers how to record Linux terminal commands using the script command.

This command allows you to record and replay all the activity in your terminal.

Using script commands can be especially helpful when you want to create a tutorial for a set of commands.

Record Linux Terminal Commands

Record Linux Terminal Commands

The script command can be run without any arguments

script

A new capturing session will start. your terminal session is saved to ./typescipt in your working directory.
When you’re done, press Ctrl+D or type the exit command to drop out of the sub-shell.

The output terminal is as follows

[vagrant@localhost ~]$ script

Script started, file is typescript
[vagrant@localhost ~]$ ls
share  typescript
[vagrant@localhost ~]$ whoami
vagrant
[vagrant@localhost ~]$ exit
exit
Script done, file is typescript
[vagrant@localhost ~]$
[vagrant@localhost ~]$ cat typescript
Script started on Sat 18 Sep 2021 08:59:49 PM +07
[vagrant@localhost ~]$ ls
share  typescript
[vagrant@localhost ~]$ whoami
vagrant
[vagrant@localhost ~]$ exit
exit

Script done on Sat 18 Sep 2021 09:00:09 PM +07
[vagrant@localhost ~]$

You can specify a different file with a script that commands an argument:

script session_`hostname`_`whoami`

The following is the output from the terminal command:

[vagrant@localhost ~]$ script session_`hostname`_`whoami`
Script started, file is session_localhost.localdomain_vagrant
[vagrant@localhost ~]$ cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
[vagrant@localhost ~]$ exit
Script done, file is session_localhost.localdomain_vagrant
[vagrant@localhost ~]$

Appending to an Existing File

Use -a flag to append your commands.

script -a session_`hostname`_`whoami`

Conclusion

You have Record Linux Terminal Commands. I hope will this your helpful. Thank you for reading the DevopsRoles page!

About HuuPV

My name is Huu. I love technology, especially Devops Skill such as Docker, vagrant, git, and so forth. I like open-sources, so I created DevopsRoles.com to share the knowledge I have acquired. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

4 thoughts on “Record Linux Terminal Commands

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.