{"id":340169,"date":"2021-09-16T18:27:25","date_gmt":"2021-09-16T15:27:25","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-record-linux-terminal-commands-with-script-cloudsavvy-it\/"},"modified":"2021-09-16T18:27:25","modified_gmt":"2021-09-16T15:27:25","slug":"how-to-record-linux-terminal-commands-with-script-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-record-linux-terminal-commands-with-script-cloudsavvy-it\/","title":{"rendered":"#How to Record Linux Terminal Commands With \u201cscript\u201d \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2e62facf558\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2e62facf558\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-record-linux-terminal-commands-with-script-cloudsavvy-it\/#Basic_Usage\" >Basic Usage<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-record-linux-terminal-commands-with-script-cloudsavvy-it\/#Appending_to_an_Existing_File\" >Appending to an Existing File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-record-linux-terminal-commands-with-script-cloudsavvy-it\/#Adding_Timing_Data\" >Adding Timing Data<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-record-linux-terminal-commands-with-script-cloudsavvy-it\/#Replaying_Sessions\" >Replaying Sessions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-record-linux-terminal-commands-with-script-cloudsavvy-it\/#Using_With_Interactive_Commands\" >Using With Interactive Commands<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-record-linux-terminal-commands-with-script-cloudsavvy-it\/#Other_Options\" >Other Options<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-record-linux-terminal-commands-with-script-cloudsavvy-it\/#Summary\" >Summary<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How to Record Linux Terminal Commands With \u201c<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">script<\/a>\u201d \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<figure style=\"width: 1200px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage size-full wp-image-14202\" srcset=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/09\/e1a7110e.jpg?width=398&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 400w, https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/09\/e1a7110e.jpg?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 1200w\" sizes=\"auto, 400w, 1200w\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/09\/e1a7110e.jpg?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Illustration showing a Linux terminal screen\" width=\"1200\" height=\"675\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><figcaption class=\"wp-caption-text\"><span class=\"type:primaryImage imagecredit\"><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.shutterstock.com\/image-vector\/linux-interface-screen-notebook-world-map-321627716\">fatmawati achmad zaenuri<\/a><\/span><\/figcaption><\/figure>\n<p>The <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/manpages.ubuntu.com\/manpages\/bionic\/en\/man1\/script.1.html\"><code>script<\/code> command<\/a> lets you record and replay activity in your terminal. It\u2019s helpful when you want to create a reference of the steps you\u2019ve taken or you\u2019re creating a tutorial for others to follow.<\/p>\n<p><code>script<\/code> outputs a typescript of all the commands you\u2019ve run. It works by dropping you into a sub-shell that logs everything you execute. Your session will be saved as plain text when you leave the shell. This makes <code>script<\/code> more reliable than redirected input streams.<\/p>\n<h2 id=\"basic-usage\"><span class=\"ez-toc-section\" id=\"Basic_Usage\"><\/span>Basic Usage<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <code>script<\/code> command can be run without any arguments:<\/p>\n<pre>script<\/pre>\n<p>A new capturing session will start. Your terminal session will be saved to <code>.\/typescript<\/code> in your working directory. You can specify a different file by giving <code>script<\/code> an argument:<\/p>\n<pre>script example_session<\/pre>\n<p>Use your shell to execute the command sequence you want to record. When you\u2019re done, press <code>Ctrl+D<\/code> or type <code>exit<\/code> to drop out of the sub-shell. You\u2019ll return to your main shell session.<\/p>\n<p>Now you can inspect the session log that\u2019s been created:<\/p>\n<pre>cat example_session<\/pre>\n<p>You\u2019ll see the output from your <code>script<\/code> session interspersed with annotations in square brackets. These annotations are used by <code>script<\/code> to record details about the terminal itself and the events that occur within it.<\/p>\n<p>As log files are plain text you can freely manipulate them in your favorite editor. Simply cut out any lines you don\u2019t want to retain or that others shouldn\u2019t see.<\/p>\n<p>This is useful if your session inadvertently outputs potentially sensitive information or you want to trim extraneous characters from the log. <code>script<\/code> records everything that happens in your terminal, including backspace presses, new lines, and control characters, some of which might not be needed in the final typescript.<\/p>\n<p><code>script<\/code> emits the name of the file it\u2019s writing to at the start and end of your session. You can disable this output by adding the <code>-q<\/code> flag to enable quiet mode.<\/p>\n<p>The <code>SHELL<\/code> environment variable is read when determining the shell to fork for the inner process. When the variable\u2019s not set, <code>script<\/code> will default to <code>sh<\/code>.<\/p>\n<h2 id=\"appending-to-an-existing-file\"><span class=\"ez-toc-section\" id=\"Appending_to_an_Existing_File\"><\/span>Appending to an Existing File<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>It\u2019s possible to append new commands to an existing typescript. This lets you \u201cpause\u201d and \u201cresume\u201d recording by exiting your sub-shell and starting a new session.<\/p>\n<p>Add the <code>-a<\/code> flag to append your commands to the specified file. <code>script<\/code> will overwrite the file\u2019s contents when the flag\u2019s not given.<\/p>\n<pre>script -a example_session<\/pre>\n<h2 id=\"adding-timing-data\"><span class=\"ez-toc-section\" id=\"Adding_Timing_Data\"><\/span>Adding Timing Data<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The basic typescript is ideal when you simply want to record your steps for later reading or sharing. <code>script<\/code> can also save timing data alongside its text log. This information can be used to replay your entire terminal session with appropriate delays between the commands.<\/p>\n<p>Run <code>script<\/code> with the <code>-t<\/code> flag to specify a path to write timings to. Timing files have a two-column format. Each entry contains the elapsed time since the last record in the first column. The second column records the number of characters that were typed, enabling accurate typing speed replays.<\/p>\n<pre>script -q -t example_session_timings example_session<\/pre>\n<h2 id=\"replaying-sessions\"><span class=\"ez-toc-section\" id=\"Replaying_Sessions\"><\/span>Replaying Sessions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <code>scriptreplay<\/code> command reads typescripts and timing files created by <code>script<\/code>. It replays their output into your terminal. The timing data will be used to match the duration of each typed character to its length in your original command sequence.<\/p>\n<pre>scriptreplay -t example_session_timings example_session<\/pre>\n<p>Some typescripts could contain unwanted delays or run at an uncomfortably slow speed. Use the <code>-d<\/code> flag to accelerate the output. All recorded timings will be divided by the number you pass.<\/p>\n<pre># Run 4 times faster&#13;\nscriptreplay -d 4 -t timings typescript<\/pre>\n<p>You can also use the <code>-m<\/code> flag to cap the maximum delay between individual updates. This lets you specify the longest allowed pause in seconds before <code>scriptreplay<\/code> will move to the next command, even if the typescript specifies a longer delay.<\/p>\n<pre># Maximum delay of 2 seconds&#13;\nscriptreplay -m 2 -t timings typescript<\/pre>\n<h2 id=\"using-with-interactive-commands\"><span class=\"ez-toc-section\" id=\"Using_With_Interactive_Commands\"><\/span>Using With Interactive Commands<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>It\u2019s not recommended to use <code>script<\/code> with heavily interactive commands. Terminal text editors, curses-based applications, and dialog prompts are likely to insert polluting garbage characters into your typescript. <code>script<\/code> focuses on capturing typical text-based output, not commands that manipulate your terminal to produce a graphical interface.<\/p>\n<p><code>script<\/code> isn\u2019t suitable for use with non-interactive shells as its inner shell is always interactive by nature. The command <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/manpages.ubuntu.com\/manpages\/bionic\/en\/man1\/script.1.html\">shouldn\u2019t be<\/a> expected to work with piped input either.<\/p>\n<h2 id=\"other-options\"><span class=\"ez-toc-section\" id=\"Other_Options\"><\/span>Other Options<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <code>-c<\/code> flag to <code>script<\/code> lets you specify a command. When this mode is used, <code>script<\/code> runs the command and captures its output, instead of forking a new interactive shell. This can be more effective at capturing output from some processes that behave differently when not directly connected to a TTY.<\/p>\n<p>The <code>-f<\/code> flag instructs <code>script<\/code> to write straight to the session log after each event. This improves safety by ensuring output is captured straightaway.<\/p>\n<p>The <code>script<\/code> manual page <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/manpages.ubuntu.com\/manpages\/bionic\/en\/man1\/script.1.html\">suggests<\/a> this flag could also be used to monitor a user\u2019s terminal in real-time, such as in a teacher and student scenario. The student would run <code>script -f<\/code>, then the teacher would use SSH to connect and stream the typescript file live.<\/p>\n<p><code>script<\/code> doesn\u2019t usually accept a symbolic link as a typescript path. The <code>--force<\/code> flag enables this behavior, instructing <code>script<\/code> to resolve hard and soft links to their destination.<\/p>\n<h2 id=\"summary\"><span class=\"ez-toc-section\" id=\"Summary\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><code>script<\/code> lets you record your terminal sessions to plain text files with accurate timing data. You can inspect, share, and print the typescripts manually, or replay them in your terminal using <code>scriptreplay<\/code>.<\/p>\n<p>The commands are included with most popular Linux distributions. They work with all terminal types but individual typescripts may not replay properly in a terminal that differs from the one used for recording. For best results, run <code>scriptreplay<\/code> in the same terminal type you used with <code>script<\/code>.\n<\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/14200\/how-to-record-linux-terminal-commands-with-script\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How to Record Linux Terminal Commands With \u201cscript\u201d \u2013 CloudSavvy IT&#8221; fatmawati achmad zaenuri The script command lets you record and replay activity in your terminal. It\u2019s helpful when you want to create a reference of the steps you\u2019ve taken or you\u2019re creating a tutorial for others to follow. script outputs a typescript of all&#8230;<\/p>\n","protected":false},"author":1,"featured_media":340170,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/09\/e1a7110e.jpg","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-340169","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/340169","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=340169"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/340169\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/340170"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=340169"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=340169"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=340169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}