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 common command scirpt in Linux

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article will explain in detail how to use the commonly used Linux command scirpt for you. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

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

How to use by default, we can start the scirpt command by typing script in the terminal.

Pungki@dev-machine:~$ scriptScript started, file is typescriptpungki@dev-machine:~$ you can also specify the target file name to record the print result.

Pungki@dev-machine:~$ script myfile

Define script file

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 do we use the script command because 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, we can record your activities through script when working with colleagues.

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

$script collaborate

Create collaborate file

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

Append the file

Record what someone is doing on the terminal. You may give your engineer or someone remote access to your system. 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

Add script to bash profile

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

Script without notification

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.

Script with notification

Exit record to exit the record 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.

This is the end of the article on "how to use scirpt in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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

Development

Wechat

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

12
Report