translated

This commit is contained in:
geekpi 2018-07-02 08:50:49 +08:00
parent 5155ad21e5
commit 937c40af2c
2 changed files with 90 additions and 92 deletions

View File

@ -1,92 +0,0 @@
translating---geekpi
How To Record Everything You Do In Terminal
======
![](https://www.ostechnix.com/wp-content/uploads/2017/03/Record-Everything-You-Do-In-Terminal-720x340.png)
A few days ago, we published a guide that explained how to [**save commands in terminal itself and use them on demand**][1]. It is very useful for those who dont want to memorize a lengthy Linux command. Today, in this guide, we are going to see how to record everything you do in Terminal using **script** command. You might have run a command, or created a directory, or installed an application in Terminal. Script command simply saves whatever you do in the Terminal. You can then view them if you want to know what you did few hours or few days ago. I know I know, we can use UP/DOWN arrow keys or history command to view previously running commands. However, you cant view the output of those commands. But, Script command records and displays complete terminal session activities.
The script command creates a typescript of everything you do in the Terminal. It doesnt matter whether you install an application, create a directory/file, remove a folder. Everything will be recorded, including the commands and the respective outputs. This command will be helpful who wants a hard-copy record of an interactive session as proof of an assignment. Whether youre a student or a tutor, you can make a copy of everything you do in the Terminal along with all outputs.
### Record Everything You Do In Terminal using script command in Linux
The script command comes pre-installed on most modern Linux operating systems. So, let us not bother about the installation.
Let us go ahead and see how to use it in real time.
Run the following command to start the Terminal session recording.
```
$ script -a my_terminal_activities
```
Where, **-a** flag is used to append the output to file or to typescript, retaining the prior contents. The above command records everything you do in the Terminal and append the output to a file called **my_terminal_activities** and save it in your current working directory.
Sample output would be:
```
Script started, file is my_terminal_activities
```
Now, run some random Linux commands in your Terminal.
```
$ mkdir ostechnix
$ cd ostechnix/
$ touch hello_world.txt
$ cd ..
$ uname -r
```
After running all commands, end the script commands session using command:
```
$ exit
```
**Sample output:**
```
exit
Script done, file is my_terminal_activities
```
As you see, the Terminal activities have been stored in a file called **my_terminal_activities** and saves it in the current working directory.
To view your Terminal activities, just open this file in any editor or simply display it using the cat command.
```
$ cat my_terminal_activities
```
**Sample output:**
As you see in the above output, script command has recorded all my Terminal activities, including the start and end time of the script command. Awesome, isnt it? The reason to use script command is its not just records the commands, but also the commands output as well. To put this simply, Script command will record everything you do on the Terminal.
### Conclusion
Like I said, script command would be useful for students, teachers and any Linux users who wants to keep the record of their Terminal activities. Even though there are many CLI and GUI to do this, script command is an easiest and quickest way to record the Terminal session activities.
And, thats all. Hope this helps. If you find this guide useful, please share it on your social, professional networks and **support OSTechNix**.
Cheers!
--------------------------------------------------------------------------------
via: https://www.ostechnix.com/record-everything-terminal/
作者:[SK][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.ostechnix.com/author/sk/
[1]:https://www.ostechnix.com/save-commands-terminal-use-demand/

View File

@ -0,0 +1,90 @@
如何记录你在终端中执行的所有操作
======
![](https://www.ostechnix.com/wp-content/uploads/2017/03/Record-Everything-You-Do-In-Terminal-720x340.png)
几天前,我们发布了一个解释如何[**保存终端中的命令并按需使用**][1]的指南。对于那些不想记忆冗长的 Linux 命令的人来说,这非常有用。今天,在本指南中,我们将看到如何使用 **script**命令记录你在终端中执行的所有操作。你可能已经在终端中运行了一个命令或创建了一个目录或者安装了一个程序。script 命令会保存你在终端中执行的任何操作。如果你想知道你几小时或几天前做了什么,那么你可以查看它们。我知道我知道,我们可以使用上/下箭头或 history 命令查看以前运行的命令。但是你无法查看这些命令的输出。但是script 命令记录并显示完整的终端会话活动。
script 命令会在终端中创建你所做的所有事件的 typescript。无论你是安装程序创建目录/文件还是删除文件夹,一切都会被记录下来,包括命令和相应的输出。这个命令读对那些想要一份交互式会话拷贝作为作业证明的人有用。无论莫是学生还是导师,你都可以将所有在终端中执行的操作和所有输出复制一份。
### 在Linux中使用 script 命令记录终端中的所有内容
script 命令预先安装在大多数现代 Linux 操作系统上。所以,我们不用担心安装。
让我们继续看看如何实时使用它
运行以下命令启动终端会话记录。
```
$ script -a my_terminal_activities
```
其中,**-a** 标志用于将输出追加到文件或 typescript并保留以前的内容。上述命令会记录你在终端中执行的所有操作并将输出追加到名为 **my_terminal_activities** 的文件中,并将其保存在当前工作目录中。
示例输出:
```
Script started, file is my_terminal_activities
```
现在,在终端中运行一些随机的 Linux 命令。
```
$ mkdir ostechnix
$ cd ostechnix/
$ touch hello_world.txt
$ cd ..
$ uname -r
```
运行所有命令后,使用以下命令结束 script 命令的会话:
```
$ exit
```
**示例输出:**
```
exit
Script done, file is my_terminal_activities
```
如你所见,终端活动已存储在名为 **my_terminal_activities** 的文件中,并将其保存在当前工作目录中。
要查看你的终端活动,只需在任何编辑器中打开此文件,或者使用 cat 命令直接显示它。
```
$ cat my_terminal_activities
```
**示例输出:**
正如你在上面的输出中看到的script 命令记录了我所有的终端活动,包括 script 命令的开始和结束时间。真棒,不是吗?使用 script 命令的原因不仅仅是记录命令,还有命令的输出。简单地说,脚本命令将记录你在终端上执行的所有操作。
### 结论
就像我说的那样,脚本命令对于想要保留其终端活动记录的学生,教师和 Linux 用户非常有用。尽管有很多 CLI 和 GUI 可用来执行此操作,但 script 命令是记录终端会话活动的最简单快捷的方式。
就是这些。希望这有帮助。如果你发现本指南有用,请在你的社交,专业网络上分享,并**支持 OSTechNix**。
干杯!
--------------------------------------------------------------------------------
via: https://www.ostechnix.com/record-everything-terminal/
作者:[SK][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.ostechnix.com/author/sk/
[1]:https://www.ostechnix.com/save-commands-terminal-use-demand/