Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the script command in Linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to use the script command in Linux, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand.

What is script?

Scirpt is a command that can make a record that is output to the terminal. This is useful for those who want to actually record terminal conversations. The record can be saved and printed later.

How to use it

By default, we can start the scirpt command by typing script in the terminal.

Pungki@dev-machine:~$ script Script started, file is typescript pungki@dev-machine:~$

You can also specify the target file name to record the print result.

Pungki@dev-machine:~$ script myfile

When you see the command prompt again, this means that the terminal will record anything printed to the terminal.

You will see the current directory, there is a file named myscript. (translated note by LCTT) the original text here is incorrect. The record file name is specified here as myfile instead of the default typescript. )

Why are we using the script command?

As mentioned earlier, the main function of the script command is to record everything. Here are two scenarios that use this command.

When working with colleagues

When working with colleagues, we can record your activities through script.

For example, we will use a print file called collaborate to complete the print:

$script collaborate

Then, after completing some tasks, if you need to send your work to another engineer, send him the file. So when another engineer needs to review what he has done, all he has to do is open the file with a text editor.

If he wants to update the file (to add to his work), he can use the-an option.

$script-a collaborate

Record what someone does in the terminal

You may give your engineer or someone remote access to your system, and to make sure your engineer is doing the right thing, you can record what he is doing on your system. To have the script command run automatically at login, we can add it to the shell environment configuration file. If you are using bash shell, add this line to your bash environment profile.

$vi ~ / .profile # run the script command to record everything # use-q for quite and-an option to append the script # / usr/bin/script-qa / usr/local/script/log_record_script

And save it. The next time he logs in to your system, the script command will run automatically and log into / usr/local/script/logrecordscript.

The-Q option allows the scirpt command to run in silent mode, and the logged-in user will not know that the script command has been run. The-an option will cause the record to be attached to the file without erasing the previous record.

If you do not use the-Q option, when the user logs in, he will receive a notification like the one shown below.

Exit record

To exit the recording activity, we can press Ctrl+D in the terminal, or type exit. Before exiting script, you will find that the size of the record file is 0 Kb, but after exiting, the file size will change.

Thank you for reading this article carefully. I hope the article "how to use script commands in Linux" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report