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:
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
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.