script Command in Linux

Learn via video courses
Topics Covered

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Overview

The script command in Linux is an incredibly useful tool that provides a way to record a shell session for later reference. It makes a typescript of everything printed on your terminal, proving handy for educational purposes or tracking your actions in a terminal session.

Syntax of script Command in Linux

The basic syntax of the script command in Linux is as follows:

Where:

  • options: These are optional flags that can modify the behavior of the script command.
  • file: This is the optional name of the file where the session will be recorded. If omitted, the output is saved to a file named 'typescript' in the current directory.
Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

Options in script Command in Linux

  1. -a, --append: Append the output to 'file' or 'typescript', retaining the prior contents.

    For example -

    This command appends the output of the script command to 'session.log'.

  2. -q, --quiet: Quiet mode, don't display the start and stop notifications.

    For example -

    This command starts a new session with the script command, and does not display the usual start and stop notifications.

  3. -c, --command: Run the 'command' rather than an interactive shell.

    For example -

    This command executes 'ls -la', and saves the output to 'file.log'.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Example Usages

  • Basic usage of script command:

    Output:

    Explanation: This command starts a new recording session. The output of this session is stored in the 'typescript' file.

  • Usage with filename:

    Output:

    Explanation: This command starts a new recording session, with the output stored in the 'mysession.log' file.

Tips

  • Be careful when recording scripts that contain sensitive information, such as passwords, as the script command will capture all input and output.

  • Consider using 'exit' command to properly end the script recording session.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Advanced Use Cases of script Command in Linux

  • Using script command with date command:

    Output:

    Explanation: This command records the terminal session and saves the output into a file with the current date as part of the name.

  • Use script command with -c option to record specific command:

    Explanation: This command runs 'ls -la' and records its output into 'directory_listing.log' file.

  • Use script command with tee to view and save the output at the same time:

    Explanation: This command runs 'ls -la', displays its output and simultaneously saves it into 'file.log'.

Conclusion

  • The script command in Linux is a powerful tool to record terminal sessions.

  • It provides various options like -a, -q, and -c to modify the command's behavior.

  • Script command is beneficial for educational purposes, documentation and tracking your actions.