DEV Community

Flávia Bastos
Flávia Bastos

Posted on • Originally published at flaviabastos.ca on

3

Send long terminal output to a log file

There are times when a command line output is too long and it’s hard to scroll through all the lines to see the beginning of the stack trace. This usually happens when you get errors and the best way to fix errors is to read the very first few lines to understand what error message you got and where the error is coming from.

The other day, a co-worker shared a tip in our Slack channel about the command script, which is a great tool to use in a case where the output is super long: it saves all the output in a log file. Then you can open it in a text editor and analyse it properly.

In the command line type:

script my\_script\_name.scr

The Unix script command will then start ” logging” the output. Then you can run the command that gave you the long output again and the script command will save everything until you type

exit

All you have to do then is to open my_script_name.scr in your favourite text editor for easy reading.

Things you should know:

– It only works on Unix systems (Mac, Linux)

– If you forget to give a file name, it will save the output in a file called ˋtypescriptˋ

– You can also pass a path with the file name, otherwise it will save in your current work directory

– For more info about this command you can read it man page (man script) or check this link out: https://www-users.cs.umn.edu/~gini/1901-07s/files/script.html

One cool thing was that I got to use this tool on that same day my co-worker shared it. I hope this is useful to you too.

The post Send long terminal output to a log file was originally posted on flaviabastos.ca

Photo: Photo by Markus Spiske on Unsplash

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more